Highlight in Blue color 'Caller' field

Bijay Kumar Sha
Giga Guru

I'm implementing below requirement but it's not happening. 

In the user table, for every user records, we've an attribute called Business Unit which is a dropdown variable as per below screenshot -

BijayKumarSha_0-1713360863437.png

So, if I'll create an incident or a service request, and if I put the caller name, then in backend it should validate, if the caller's Business Unit is Technology or Marketing, then the name should be appear in Blue color instead of regular black color. For others, it should be as it is like black color.

How I can implement this?

 

1 ACCEPTED SOLUTION

I've updated the below code in Client script and it's working fine. Thanks for providing the required details. It's really helpful

BijayKumarSha_1-1713521916797.png

 

View solution in original post

8 REPLIES 8

Krushna R Birla
Kilo Sage

Hi @Bijay Kumar Sha 

 

To achieve this, you need to create one on-change client script on incident table for field caller. In that script you have to use GlideAjax method which will call client callable script include. Pass the value of caller as one of the parameter.

 

You need to create one client callable script include, create one function which validates whether user has technology business unit or not by simply gliderecord on sys_user table.

 

Then, in client script use your response to highlight field. If response is yes then highlight caller field.

Ex : control.style = 'background-color: blue';

 

If response is not then in else part use,

control.style = 'background-color: black';

 

Please try to explore glideajax and script include concept at your own, this will help you to boost your knowledge in servicenow. 

 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Krushna R Birla
Kilo Sage

@Bijay Kumar Sha 

 

For your reference, I quickly try to write code which you can refer 

 

//Script Include function
validateBusinessUnit: function() {
var caller = this.getParameter('sysparm_caller');
var gr = new GlideRecord('sys_user');
if (gr.get(caller)) {
if (gr.u_business_unit == 'Technology') {
return 'YES';
} else {
return 'NO';
}
}
}

//Client Script
var ga = new GlideAjax('<script_include_name>');
ga.addParam('sysparm_name', 'validateBusinessUnit');
ga.addParam('sysparm_caller', newValue);
ga.getXml(callback);

function callback(response) {
var ans = response.responseXML.documentElement.getAttribute('answer');
if (ans == 'YES') {
control.style = 'background-color: blue'; //control.style.backgroundColor = 'blue';
} else {
control.style = 'background-color: black'; //control.style.backgroundColor = 'black';
}
}
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Hi @Krushna R Birla , Thank you for your response. I'm getting below error message -

BijayKumarSha_0-1713427949139.png

 

This error message got disappear. Because I've updated in the client script from ga.geXml to ga.getXML... However, there is no change in the color option in the caller field. I'm just providing the Script Include and OnChange Client Script as below - 

BijayKumarSha_0-1713441598863.pngBijayKumarSha_1-1713441665577.png

Please let me know what I'm missing here.