the client script is not working in service portal but working in try it option in catalog form

Ponnada
Tera Contributor
I created a on change catalog client script such that based on requested fors country and the options he chose in domain ,category and service fields(reference) will make a particular value be set and read only in service desk filed. Please take a look at the below script and help me out.
 
 
 
Ponnada_0-1691502870938.pngPonnada_1-1691502997518.pngPonnada_2-1691503056356.png

 

4 REPLIES 4

Sagar Pagar
Tera Patron

Hi @Ponnada,

 

Make sure that UI type is All.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hi Sagar,

 

I did chose All in UI Type but still it is not working.

 

Best,

Kasthuri

Tushar
Kilo Sage
Kilo Sage

Hi @Ponnada 

 

can you please paste the script here, so that I can go through and help you further on this.

 

Thanks.

Hi Tushar,

 

here is the script i wrote and I did select UI type as ALL:

 

function onChange(control, oldValue, newValue, isLoading) {
 
// Not setting field when form loads with the Requested For set as the logged in user - removing this
//if (isLoading) {
// return;
//}
 
if (newValue == '') {
g_form.clearValue('service_desk');
g_form.setReadOnly('service_desk',  false);
return;
}
 
// Type appropriate comment here, and begin script below
 
// When the Requested For changes, set the Service Desk based on location
// OU Code = OU20018698 --> URUGUAY - TI - PRONTO MESA DE SERVICIO (c957007a479fdd10ea4d0bde536d437b)
// CR --> Costa Rica - ITBS - Centro de Servicio Costa Rica (8c4e1131db693308a0c054195e961916)
// PA --> Panama - ITBS - Centro de Servicio Panama (15a41b77db65bf0095c83e4f9d9619f3)
// MX --> GTS - EUS - End User Support MX (34723e041b0fcd10ca0b32a61a4bcb95)
// UY --> URUGUAY - TI - PRONTO MESA DE SERVICIO (c957007a479fdd10ea4d0bde536d437b)
//  UY --> URUGUAY,DOMAIN -->PRONTO,CATEGORY-->"Backoffice IT - Data Operations"/"Backoffice IT - Production" -URUGUAY - PRONTO - IT - PRODUCCION
//  UY --> URUGUAY,DOMAIN -->PRONTO,CATEGORY-->"Backoffice IT - Technology" -URUGUAY - PRONTO - IT - TECHNOLOGIA
//  UY --> URUGUAY,DOMAIN -->PRONTO,CATEGORY-->"Technology Support" - URUGUAY - PRONTO - IT - SERVICIO TECNICO
 
 
 
var requested_for = g_form.getReference('requested_for', setFields);
 
 function setFields(requested_for) {
var ou_code = requested_for.u_org_unit.toString();
var country = requested_for.country.toString();
g_form.setDisabled('service_desk',false);
g_form.setReadOnly('service_desk',false);
if (ou_code == 'OU20018698') {
 
g_form.setValue('service_desk', 'c957007a479fdd10ea4d0bde536d437b');
//g_form.setReadOnly('service_desk', true);
}
 
else if (country == 'CR' || country == 'PA' || country == 'MX' || country == 'UY') {
 
if (country == 'CR') {
g_form.setValue('service_desk', '8c4e1131db693308a0c054195e961916');
}
 
else if (country == 'PA') {
g_form.setValue('service_desk', '15a41b77db65bf0095c83e4f9d9619f3');
}
 
else if (country == "MX") {
g_form.setValue('service_desk', '34723e041b0fcd10ca0b32a61a4bcb95');
}
 
else if (country == "UY") {
var domain = g_form.getValue('domain').toString();
var domainLabel=getDomain(domain);
var category = g_form.getValue('category').toString();
var categoryLabel=getCategory(category);
var service = g_form.getValue('service').toString();
var serviceLabel=getService(service);
 
 
if (country == "UY" && domainLabel == "PRONTO" && categoryLabel =="Backoffice IT" && (serviceLabel =="Data Operations"||serviceLabel =="Data Operations"|| serviceLabel =="Production")) {
g_form.setValue('service_desk', '75c0151d97279990840c77100153af4d');
}
else if (country == "UY" && domainLabel == "PRONTO" && categoryLabel =="Backoffice IT" && serviceLabel =="Technology") {
g_form.setValue('service_desk', '9618e012476f11d0ea4d0bde536d4316');
//9618e012476f11d0ea4d0bde536d4316
else if(country == "UY" && domainLabel == "PRONTO" && categoryLabel =="Technical Support"){
g_form.setValue('service_desk', '36686492476f11d0ea4d0bde536d4374');
}
else { 
g_form.setValue('service_desk', 'c957007a479fdd10ea4d0bde536d437b');
}
 
}
 
}
          else {
          
g_form.clearValue('service_desk');
g_form.setReadOnly('service_desk',  false);
 
 
// g_form.setValue('service_desk', 'c957007a479fdd10ea4d0bde536d437b');
}
 
function getDomain(domain)
{
var gr = new GlideRecord('sys_choice');
gr.addQuery('name', 'question_choice');
gr.addQuery('element','eus_latam_domain');
gr.addQuery('inactive','false');
gr.addQuery('sys_id',domain.toString());
gr.query();
 
while (gr.next()) {
return gr.label;
}
}
 
function getCategory(category)
{
var gr = new GlideRecord('sys_choice');
gr.addQuery('name', 'question_choice');
gr.addQuery('element','eus_latam_category');
gr.addQuery('inactive','false');
gr.addQuery('sys_id',category.toString());
gr.query();
 
while (gr.next()) {
return gr.label;
}
}
 
function getService(service)
{
var gr = new GlideRecord('sys_choice');
gr.addQuery('name', 'question_choice');
gr.addQuery('element','eus_latam_service');
gr.addQuery('inactive','false');
gr.addQuery('sys_id',service.toString());
gr.query();
 
while (gr.next()) {
return gr.label;
}
}
}