Display specific user depending on the application selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 03:11 AM
Hi all,
I have two fields on my service catalog: application and custodian.
What I would like to do is to display a specific user under the custodian field depending on which application was selected (the application field is a dropdown list of values).
I am new to the ServiceNow processes so I appreciate and kind of help.
Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 03:19 AM
Hi @Carol_123 ,
You need to populate one field based on other field in service catalog, so you can use the catalog client script and glideajax
- If you want to auto populate the value in another field on same form, you can use catalog client script.
var myVar = g_form.getValue('field-name1');
and set in another field using
g_form.setValue('field-name2',myVar );
- If your business need to fetch value form the table you can use the callback function or use GlideAjax.
Refer this thread for GlideAjax example auto populate values based on another field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2022 03:46 AM
Hello Carol,
You can use "onChange" Catalog client script to initially get the value from your application field, and then send it to a script include via GlideAjax call. Make sure the script include is client callable for the same. Then put your conditions and send the value back to client catalog script and then set it to the custodian field. I have implemented your requirement via an example. Here, I am passing Abraham Lincoln as user if application is not Global and if application is global I will be passing Abel Tuter as user.
Client catalog script:
function onChange() {
//Type appropriate comment here, and begin script below
var application= g_form.getValue('application');
var ga = new GlideAjax('global.ScriptIncludeExampleThree');
ga.addParam('sysparm_name', 'refqual');
ga.addParam('app', application);
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
g_form.setValue('custodian', answer);
}
}
Script Include function:
refqual:function() {
gs.log("lolatleastscripy");
var application= this.getParameter('app');
if(application=="global")
{
return "62826bf03710200044e0bfc8bcbe5df1";
}
else
{
return "a8f98bb0eb32010045e1a5115206fe3a";
}
}
Script Include:
Result when application not global:
I hope this Information help you, If you find this information helpful please mark this as helpful and accept the solution. Thank you