0

Grabbing query string values is easy in SharePoint with some javascript...

var xid = GetUrlKeyValue("ItemId", false, location.href);

But what if ItemId didn't exist in certain instances, how can you code in some logic to first determine the query string item exists, and branch accordingly? I've tried a few approaches, but not having any luck.

if ((typeof xid!== "undefined") && (xid!== null)) {
        alert(xid);
    } else {
        alert("undefined");}

and

if (typeof xid === "undefined") {
        alert("undefined");
    } else {
        alert("defined");}

Am I on the right track here?

2

GetUrlKeyValue function in SharePoint is defined in init.js.

If the key is not found in the specified URL then it returns an empty string("").

So, you can check it simply like below:

if(xid) {
    alert("Found.");
} else {
    alert("Not Found").
}

Or

if(xid == "") {
    alert("Found.");
} else {
    alert("Not Found").
}
  • Does this answers your question? – Ganesh Sanap May 16 at 10:26
0

Try with the below code :

if ((typeof xid!== undefined) && (xid!== null)) {
    alert(xid);
} else {
    alert("undefined");}
0

Oddly enough couldn't get these working. Ended up just using if(xid == "")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.