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

Display specific user depending on the application selected

Carol_123
Tera Contributor

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.

2 REPLIES 2

Community Alums
Not applicable

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

 

 

Taha Habib
Tera Guru

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);	
}	

	
}

 

TahaHabib_0-1672141366514.png

 

 

Script Include function:

refqual:function() {
		gs.log("lolatleastscripy");
		var application= this.getParameter('app');
		if(application=="global")
		{
			return "62826bf03710200044e0bfc8bcbe5df1";
		}
		else
		{
			return "a8f98bb0eb32010045e1a5115206fe3a";
		}	
	}

Script Include:

TahaHabib_1-1672141478784.png

 

Result when application not global:

 

TahaHabib_2-1672141527549.png

 

I hope this Information help you, If you find this information helpful please mark this as helpful and accept the solution. Thank you