Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Catalog Client Script not working properly in Service Portal (Kingston)

Sri63
Mega Expert

Catalog Client Script on Catalog Item is not working 

Below is the error that I am getting when I check in INSPECT from browser debugging.find_real_file.png

Here is the Code that I wrote in the CLIENT SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {
         if (isLoading || newValue == '') {
            return;
         }
         var results=[];
         var servic = g_form.getValue('u_claimservices');
         var gvp = g_form.getValue("u_gvp");
         var network = g_form.getValue('u_network');
         var usr = g_user.userID;
         var classs=g_form.getValue('u_class');
         results=getScopeFilter(servic,gvp,network,classs,usr);
//alert(results);
         results=results.split('$@@@$');
//alert(results[0]);
//alert(results[1]);
         setFilter('u_appselector',results[0]);
         if(results[1]!='')
             {           setFilter('u_exclusion',results[1]);
         }
         function setFilter(listName,filter) {
         window[listName + 'g_filter'].reset();
         window[listName + 'g_filter'].setQuery(filter);
         window[listName + 'acRequest'](null);
         }
}


Steps I did in CMS:
1. Catalog Client Script: Written in CMS 
2. UI Type as : All
3. Catalog Client Script Type: onChange

We are moving our Service Catalog from CMS into Service Portal
1.Current Process in CMS : [ There are couple of choice list fields in which when selected each there is logic that filters behind and generated appropriate result in LIST COLLECTOR ]


Issues facing in Service Portal
    a. JavaScript Client Script Error (as shown in the above picture)
    b. I would like to view List Collector in Service Portal, but many said that we wont see the same view no more in Service Portal. (Any suggestions to obtain this view) ??

Can some one help me on how to resolve these two issues.

 

Thanks

 

1 ACCEPTED SOLUTION

Sri63
Mega Expert

Hi All,

Thanks everyone for your suggestions.

 

Problem is solved !!!!

 

Steps followed:

Step 1:

1. Added Dependency to my Service Portal 

    a. Service portal --> Dependencies --> New

    b. Give a Name to your dependency

        Check [include on page load]

        Portals for page load [add your portal page]

    c. JS Include

       Create a new JS Include

       Add your UI Script to that JS Include

    d. Save

 

Step 2:

I have made few changes to my Client Script

Basically changed my logic like:

 

// This is for Service Portal 

try{

.....

... <logic>

}

// This is for CMS

Catch(e){

....

... <logic>

}

 

Step: 3

   a. Go to the Widget which is included in you page

   b. Scroll Down -> Click Related Dependencies

   c. Click "Edit"

   d. Add the JS Included which we created in the above step

   e. Save 

 

 

By doing this it has resolved the issue

View solution in original post

14 REPLIES 14

SanjivMeher
Kilo Patron
Kilo Patron

In the client script getScopeFilter is missing. It should be a function which should be in the same client script or must be an UI script


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,

Thanks for your quick response. I have written in "UI SCRIPT". I am still getting the same error

Below is the code from UI Script:

function getScopeFilter(service,gvp,network,classs,usr,declaration,scopeName)
{
var filter1='';
var filter2='';
var filter3='';
var networks=network;
if(networks == 'a7e85c9f0f667100a9b2e388b1050e19')
networks = networks+'^ORcompany=74fd1f820fd9d2c0a9b2e388b1050ecc';

if(networks!='')
{
filter1+='^company='+networks;
filter2+='^company='+networks;
filter3+='^u_company='+networks;
}
if(gvp!='')
{
filter1+='^u_gvps='+gvp;
filter2+='^u_gvps='+gvp;
filter3+='^u_gvp='+gvp;
}

if(classs!='')
{
filter1+='^sys_class_name='+classs;
filter2+='^sys_class_name='+classs;
if(classs=='cmdb_ci_database'){
filter3+='^u_sub_category=Database';
}else if (classs=='cmdb_ci_linux_server'){
filter3+='^u_sub_category=Linux Server';
} else if (classs=='cmdb_ci_win_server'){
filter3+='^u_sub_category=Windows';
} else if (classs=='cmdb_ci_unix_server')
{ filter3+='^u_sub_category=Unix Server';
} else if (classs=='cmdb_ci_server')
{ filter3+='^u_sub_category=Linux Server^ORu_sub_category=Unix Server^ORu_sub_category=Windows';
} else if (classs=='cmdb_ci_netgear')
{ filter3+='^u_sub_category=Network Gear';
} else if (classs=='cmdb_ci_computer')
{ filter3+='^u_sub_category=Workstations';
}}

if(service == "unclaim"){
filter1 +='^managed_by='+usr+'^ORu_gvps='+usr+'^u_claim_the_device=true';
filter2='';
filter3='';
}
else if(service == "claim"){
filter1 += '^managed_byISEMPTY';
filter2='';
filter3='';
}
else if(service == "pci_nonpci"){
filter1 +='^managed_byISNOTEMPTY^u_pcis=No^u_claim_the_device=true';

filter2+='^managed_byISNOTEMPTY^u_pcis=Yes^u_claim_the_device=true';
filter3='';

}
else if(service == "internal"){

filter1 +='^managed_byISNOTEMPTY^u_exposed_to_internets=Internal^u_claim_the_device=true';

filter2+='^managed_byISNOTEMPTY^u_exposed_to_internets=External^u_claim_the_device=true';
filter3='';
}
else if(service == "auditpci_nonpci"){
filter1 +='^managed_byISNOTEMPTY^u_audit_pci=false^u_claim_the_device=true';
filter2+='^managed_byISNOTEMPTY^u_audit_pci=true^u_claim_the_device=true';
filter3='';
}



if(declaration== 'delete' || declaration== 'add'){
var device = new GlideRecord('u_scope_declaration_device');
device.addQuery('u_scope_name',scopeName);
device.query();
if(declaration == 'delete'){
filter1 += '^sys_idIN';
filter3 += '^sys_idIN';
while(device.next()){
if( device.u_unclaimed_device==''){
filter1 += device.u_device_name + ',';
}
else{
filter3 += device.u_unclaimed_device+ ',';
}}
}
else if(declaration == 'add'){
while(device.next()){
if( device.u_unclaimed_device==''){
filter1 += '^sys_id!='+device.u_device_name;
}else{
filter3 += '^sys_id!='+device.u_unclaimed_device;
}
}
filter1= filter1.slice(0, filter1.length-1);
}}
filter1=filter1.slice(1,filter1.length);
if(filter2!='')
{
filter2=filter2.slice(1,filter2.length);
}
if(filter3!='')
{
filter3=filter3.slice(1,filter3.length);
}
return filter1 +"$@@@$"+filter2+"$@@@$"+filter3;

}

Brad Tilton
ServiceNow Employee
ServiceNow Employee

How are you including the ui script on the page?

And btw. you shouldn't do GlideRecord calls from a UI Script either since it's on the client side.

 

//Göran