Client Script to recognize User domain and post field messages not working

chadp
Mega Contributor

I have a need to display different messages based off User domain for Priority field changes from Users.

However,   nothing I have tried seems to work to identify the User domain. I have attempted querying the Glide Record, I have attempted (str.includes) method as well. Beating my head against a wall.

Below is the script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

//If the page isn't loading and user is not itil

var isITIL = g_user.hasRole('itil');

var domainGet = g_form.getValue('incident.company');

var companyCheck = domainGet.includes("CompanyName");

if (!isLoading && (!isITIL) && (!companyCheck)){

//If the new value isn't blank

if(newValue == 1) {

//Type appropriate comment here, and begin script below

alert('Severity 1 indicates you are identifying a production system is unavailable. Please contact the Hitachi Service Desk');

}

if(newValue == 2) {

//Type appropriate comment here, and begin script below

alert('Severity 2 indicates your are identifying an issue including degraded system performance affecting all users. Please contact the Hitachi Service Desk');

}

}

else if (!isLoading && (!isITIL) && (companyCheck))

{

//If user is Avara ESS and form is not loading.

if(newValue == '1') {

//Type appropriate comment here, and begin script below

g_form.showFieldMsg("incident.priority",'Priority 1 (Critical): Any major failure like an entire site down or service not functioning, and the incident affects the entire organization or a large number of users.');

}

else if(newValue == '2') {

//Type appropriate comment here, and begin script below

g_form.showFieldMsg("incident.priority",'Priority 2 (High): Any failure like a site or service not functioning or performance is degraded, and the incident affects an entire building or a department, or a significant numbers of users.');

}

else if(newValue == '3') {

g_form.showFieldMsg("incident.priority",'Priority 3 (Medium): Incidents affecting non-critical systems.   No impact on live service or business operations. The incident affects multiple or more than one end user.');

}

else if(newValue == '4') {

g_form.showFieldMsg("incident.priority",'Priority 4 (Low): Normal incidents affecting a non-critical system.   No impact on live service or business operations. The incident usually affects only a single user and can be critical to that end user.');

}

else if(newValue == '5') {

g_form.showFieldMsg("incident.priority",'Priority 5 (Very Low): Intermittent issues affecting a single user, or for requesting how to advice or general inquiry.');

}

}

}

3 REPLIES 3

Deepak Kumar5
Kilo Sage

You have to set the user domain value in scratchpad variable in Display business Rule and use that variable in your client script.



var myUserObject = gs.getUser()


myUserObject.getDomainID() -- returns the domain ID of the current user


myUserObject.getDomainDisplayValue() -- returns the domain display value for the current user



Display business-rules



Also Dot walk is not supported in client side code.


var domainGet = g_form.getValue('incident.company');


Thanks Deepak Kumar,



Honestly not experience with using the scratchpad ,



So my script for identifying the Incident record Company field info will need to be in a business rule and called using scratchpad in the Client Script... is that correct?


Hello Chad,



The scratchpad works sort of like a global variable on the form.   So, you could do something like this in a display Business Rule:



var myUser = gs.getUser();


g_scratchpad.domain_id = myUser.getDomainID();


g_scratchpad.domain_display_value = myUser.getDomainDisplayValue();



Then, in your client script, you call the g_scratchpad.domain_id just like any other variable.



if(g_scratchpad.domain_id == approvedDomainID){


        return true;


}



Hope that helps clear things up!