The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Why the request for field is populated with the current login user

Alon Grod
Tera Expert

When I created a new catalog item request, the request for field of the sc_request table is populated automatically with the current login user instead of the taking the value from the request for variable. How can I make sure that this field will populate automatically with the request for variable from the catalog item. Again, Im talking about sc_request table.

20 REPLIES 20

@Alon Grod ,

 

I have reproduced the same scenario in my PDI and I am getting this error, could you please share the screenshot where are you getting this error.

Also please share the screenshot of your business rule!

I was tried in the backend to reproduce the same

 

 

@Prince Arora Im getting this immediately after I click Submit on the catalog item request.
The BR is on before insert on sc_request table with this script:

var ritm = new GlideRecord('sc_req_item'); 
ritm.addQuery('request', current.sys_id); 
ritm.query(); 
while (ritm.next()) { 
if (!JSUtil.nil(ritm.variables.requested_for)) { 
current.requested_for = ritm.variables.requested_for;
} 
}


Any ideas? @Prince Arora  

@Alon Grod 

you should use after insert on RITM

var ritm = new GlideRecord('sc_req_item'); 
ritm.addQuery('sys_id', current.sys_id); 
ritm.query(); 
if (ritm.next()) { 
	if (!JSUtil.nil(ritm.variables.requested_for)) { 
		ritm.requested_for = ritm.variables.requested_for;
		ritm.update();
	} 
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello @Alon Grod 

 

As suggested by @Ankur Bawiskar , please set the condition of the Business Rule to After and include "ritm.update()" in the last line; in this case, the default value logic will be executed first, followed by the update of the "requested_for" with your business rule. In this case, the error message may not be displayed!

Though it has worked for me in the before-insert Business rule in my PDI(without error)

Please give it a try!

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Alon Grod 

it's because of OOB default value on that field on sc_request

you can set the field using workflow run script

var req = current.request.getRefRecord();

req.requested_for = current.variables.variableName;

req.update();

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader