Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

what could we use in the Business Rule script similar to the client side scripting which uses g_form.getValue('o_employee'); //'o_employee' is a variable in service request?

Raju Singh1
Tera Expert

Hi Experts,

I have an onoload client script which calls a script include which populates the value of the variable in the service request

qrykey = 'type=keyboard^install_status=1^assigned_to='+g_form.getValue('o_employee');      //'o_employee' is a variable

// in service request

 ga = new GlideAjax('KPopulateEmployeeAssets');
  ga.addParam('sysparm_name','populateKeyboard');
  ga.addParam('sysparm_table_name',"cmdb_ci_peripheral");
  ga.addParam('sysparm_encoded_query', qrykey);
  ga.getXMLAnswer(function(answer)
  {
   var str = answer.slice(0,-1);
   g_form.setValue('o_asset_keyboard',str);
  });
 
I want to use the same script in the business Rule, but I am not sure what shall I put in this place '+g_form.getValue('o_employee');      //as g_form is used in client script. What shall I use in Business Rule in place of this.

 

9 REPLIES 9

Hi Ashutosh,

The above code didn't work.

BR is on the User table (sys_user) after update but the 'o_employee ' is the variable in the Requested item. This requested item is created on after Update business Rule of User table(sys_user) table.

 

To add here,

The onload client script works perfect with the below code. but since I am trying to use the same client script for my business Rule. I should replace g_form int the qrykey. I tried different options But it doesn't work.

 

qrykey = 'type=keyboard^install_status=1^assigned_to='+g_form.getValue('o_employee');      //'o_employee' //is a variable

// in service request

 ga = new GlideAjax('KPopulateEmployeeAssets');
  ga.addParam('sysparm_name','populateKeyboard');
  ga.addParam('sysparm_table_name',"cmdb_ci_peripheral");
  ga.addParam('sysparm_encoded_query', qrykey);
  ga.getXMLAnswer(function(answer)
  {
   var str = answer.slice(0,-1);
   g_form.setValue('o_asset_keyboard',str);
  });

 

 

Hi,

 

Then try this :

 

current.o_asset_keyboard = str;

 

If this is a before insert/update BR dont use current.update and use current.update in after BR

Thanks,
Ashutosh Munot

This didn't work either.

 

Hi,

 

Are you getting Value in STR?


Thanks,
Ashutosh

I achieved it though glide record.