I have a requirement to create a catalog item to update sys_user table fields. Based on data entered on the variables on catalog item User record fields must be updated.

jyotsna1
Giga Contributor

I have a requirement to create a catalog item to update sys_user table fields. Based on data entered on the variables on catalog item User record fields must be updated.

Example: I a variable 'Phone Number' is filled by user on catalog form and submits the form, all the variables should be passed to the REQ description and value updated in 'Phone Number' variable should update 'Business phone' field in the User(sys_user) table.

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You can have an after insert/update Business rule that runs on RITM (sc_req_item) table that will GlideRecord User table with appropriate query & update required fields.

When Item | is | Your item name here

so that it runs only for specific catalog item for which you want details to be updated on user table.

Sample script.

(function executeRule(current, previous /*null when async*/) {

var usris=new GlideRecord('sys_user');
usris.addQuery('sys_id',current.variables.requested_for);//considering requested for variable has user whse details are to be update
usris.query();
if(usris.next())
{
 usris.phone=current.variables.phonevariablename; //replace phonevariablename with correct vriable name that stores phone
usris.update();
}
})(current, previous);

Hi Jaspal,

I created after insert business rule to run on sc_request table (as we are not using RITM) when catalog item is "Catalog to refresh User Details", to update phone number entered on catalog form to user record. But it did not update my user record. Please help .

(function executeRule(current, previous /*null when async*/) {

var usris=new GlideRecord('sys_user');
usris.addQuery('sys_id',current.variables.user_id);
usris.query();
if(usris.next())
{
usris.phone=current.variables.new_business_phone_number;
usris.update();
}
})(current, previous);

 

 

johnfeist
Mega Sage
Mega Sage

Hi Jyostsna,

You actually have two requirements here, one to update the description in sc_request and the other apply the update(s) in sys_user.

Assuming that you are driving of the sc_req_item record you can accomplish these in a Business Rule as follows:

var theRequest = new GlideRecord("sc_request");
	theRequest.get(current.parent);
	theRequest.description = theRequest.description + <add your information>;
	theRequest.update();

	var theUser = new GlideRecord("sys_user);
	theUser.get(theRequest.requested_for);
	<put in your changes.
	theUser.update();

You can set the conditions for the business rule firing to correspond to the item or whatever else is needed.  I haven't tested the code above so there may be a fat finger or two in it.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster