Why the request for field is populated with the current login user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 04:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 11:38 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 07:21 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 07:54 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 08:00 AM - edited ‎04-17-2023 08:13 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2023 10:10 PM
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();
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader