Make variable set catalog script disable for one catalog item.

prabhmeet
Giga Expert

Hi,

 I have a variable set which is being used in three catalog items. There is a client script in the variable set, that I want to disable for one of the catalog items. What script can I write so that the code does not work for one of the catalog items?

1 ACCEPTED SOLUTION

Brian Rosfelde1
Giga Expert

You could try adding an if statement around your block of code along the lines of: 

if(current != <catalog_sys_id>){

//your code block here

The <catalog_sys_id> would be the sys_id for the catalog item you want to disable this code for. 

 

View solution in original post

4 REPLIES 4

Brian Rosfelde1
Giga Expert

You could try adding an if statement around your block of code along the lines of: 

if(current != <catalog_sys_id>){

//your code block here

The <catalog_sys_id> would be the sys_id for the catalog item you want to disable this code for. 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Prabh,

you can do following:

1) in the onLoad catalog client script get the URL

2) determine the sys id of the catalog item from the url parameter sysparm_id

if it is the one you are looking for then make all variables readonly

function onLoad(){

var ritmSysId = getParmVal('sysparm_id');
if(ritmSysId == '<sysId>'){
 
g_form.setReadonly('<variableName>', true);
}

}

function getParmVal(name){
    var url = document.URL.parseQuery();
    if(url[name]){
        return decodeURI(url[name]);
    }
    else{
        return;
    }
}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Abhinay Erra
Giga Sage

get the sys_id of the catalog item from the url and as Brian mentioned restrict the code from running if the sys_id matches to the one you are looking for.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Prabh,

Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.

Regards
Ankur

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