The CreatorCon Call for Content is officially open! Get started here.

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 for's 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. I did select UI type as ALL and cannot change the whole script but can add to the existing one I added my script after the MX country. I would like the answer ASAP ,as I am running out of time:

 

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;
}
}
}
9 REPLIES 9

Peter Bodelier
Giga Sage

Hi @Ponnada,

 

You are trying to do synchronous queries in the functions getDomain, getCategory and getService. This is not going to work. You will have do these asynchronous.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Ponnada
Tera Contributor

Hi @Peter Bodelier

 

How do I do asynchronous queries in function getDomain,getCategory and getService? I have never done it before .Could you please help me out.

 

Best,

Kasthuri

Kasthuri

Hi @Ponnada,

 

It somewhat the same as the getReference you have used.
Take a look at the API Documentation for an example. 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi @Peter Bodelier

 

Are we talking about something like the below script:

function onChange(control, oldValue, newValue, isLoading) {
if (newValue === '') {
g_form.clearValue('service_desk');
g_form.setReadOnly('service_desk', false);
return;
}

var requested_for = g_form.getReference('requested_for', setFields);

function setFields(requested_for) {
var country = requested_for.country.toString();
g_form.setDisabled('service_desk', false);
g_form.setReadOnly('service_desk', false);

if (country === "UY") {
g_form.getReference('domain', setDomain);

function setDomain(domain) {
var domainValue = domain.name.toString();
g_form.getReference('category', setCategory);

function setCategory(category) {
var categoryValue = category.name.toString();
g_form.getReference('service', setService);

function setService(service) {
var serviceValue = service.name.toString();

if (domainValue === "PRONTO" && categoryValue === "Backoffice IT" &&
(serviceValue === "Data Operations" || serviceValue === "Production")) {
g_form.setValue('service_desk', '75c0151d97279990840c77100153af4d');
g_form.setReadOnly('service_desk', true);
} else if (domainValue === "PRONTO" && categoryValue === "Backoffice IT" && serviceValue === "Technology") {
g_form.setValue('service_desk', '9618e012476f11d0ea4d0bde536d4316');
g_form.setReadOnly('service_desk', true);
} else if (domainValue === "PRONTO" && categoryValue === "Technical Support") {
g_form.setValue('service_desk', '36686492476f11d0ea4d0bde536d4374');
g_form.setReadOnly('service_desk', true);
}
}
}
}
}
}
}