We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

extracting catalog item url values from esc portal

Deepika54
Tera Contributor

Hello experts,

 

When clicked on a catalog item url from esc portal, it is opening as a below link

 

Deepika54_0-1764875682647.png

 

Is there any way by which we can extract the short_descripton value from the URL itself highlighted in yellow via any catalog client script. plz help

2 ACCEPTED SOLUTIONS

fred183gC
Tera Sage

Hi @Deepika54 ,

Here is a catalog client script that runs onLoad extracts the short_description value from the URL:

function onLoad() {
    var short_description = getParmVal('short_description'); //URL parameter
    if (short_description) {
        g_form.setValue('variable_name', short_description); //Set Variable
    }
}

function getParmVal(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(top.location);
    if (results == null) {
        return "";
    } else {
        return unescape(results[1]);
    }
}

 

View solution in original post

Ankur Bawiskar
Tera Patron

@Deepika54 

you can achieve this without RegEx and use OOTB Class URLSearchParams

function onLoad() {

    var url = top.location.href;
    var shortDescription = new URLSearchParams(url).get("short_description");
    alert(shortDescription);
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

fred183gC
Tera Sage

Hi @Deepika54 ,

Here is a catalog client script that runs onLoad extracts the short_description value from the URL:

function onLoad() {
    var short_description = getParmVal('short_description'); //URL parameter
    if (short_description) {
        g_form.setValue('variable_name', short_description); //Set Variable
    }
}

function getParmVal(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(top.location);
    if (results == null) {
        return "";
    } else {
        return unescape(results[1]);
    }
}

 

you are the best

Ankur Bawiskar
Tera Patron

@Deepika54 

you can achieve this without RegEx and use OOTB Class URLSearchParams

function onLoad() {

    var url = top.location.href;
    var shortDescription = new URLSearchParams(url).get("short_description");
    alert(shortDescription);
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader