Copied User Email, Department from user table to Catalog form based on Requested For VariableSet

Rajesh Bandila
Tera Contributor

Hi,

 

I need to populate the User Email, Department based on Requested For field on catalog item form. But the Requested For field is in VariableSet. I written the below OnChange catalog Client script and it did't work. Please give me an correct code to get the field values from user table based on Requested For VariableSet?

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var requestedForVar = g_form.getVariable('requested_for'); // replace 'requested_for' with your variable name
   g_form.getReference(requestedForVar, callBack);

   function callBack(user){
      g_form.setVariable('user_dep', user.department); // replace 'user_dep' with your variable name
      g_form.setVariable('user_email', user.email); // replace 'user_email' with your variable name
   }
}
7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Rajesh Bandila 

 

I am not 100% sure, but did you try with auto populate feature on Variable ? 

AGLearnNGrow_0-1708344508935.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Thanks @Dr Atul G- LNG ,

 

I had tried by using Auto Populate option, But It's not allowing to select the Requested For field. I'm thinking Auto Populate is not allowing for Variable Set.

 

Thanks&Regards,

Rajesh B

Hi @Rajesh Bandila 

 

I tried in variable set ( Single Row)

AGLearnNGrow_0-1708368909431.png

With MRVS

 

AGLearnNGrow_1-1708369026823.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Rajesh Bandila ,

 

Please use Autopopulate feature provided by ServiceNow available from Utah Version. you can see below link how it can be used.

https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

 

Thanks,

Danish