Requested for on RITM is not updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 03:24 AM
Hi,
I have a requirement to update the 'Requested for' (on both REQ and RITM) filed based on what is entered in the 'contact' field in the catalog item during the request submission.
For example: ABC is a catalog item and there is a field called 'contact' in the item which is a reference to the 'user' table. During the request submission if I choose 'Abel' in contact field and submit the request, the 'requested for' of the REQ and RITM should be updated to 'Abel' not the logged in user.
For this I have written the script in the workflow.
Below is the script:
var reqRecord = current.request.getRefRecord();
reqRecord.requested_for = current.variables.request_for;
reqRecord.update();
This was working earlier but not sure why it isn't working now. No matter what I select in the 'contact' field the 'requested for' of the REQ and RITM is set to the logged in user.
Could this be because of the 'San Diego' version or the patch upgrades?
Is there any way I can achieve this may be using a business rule?
Requesting the suggestions, Thank you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 12:37 AM
If it worked after insert and did not work in workflow that means there is some after insert BR running on either request or RITM table which is setting the value of requested for. The reason could be the workflow executing before BR and BR overwriting the value of requested for to current loggedin user.
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2022 11:05 PM
@Blessy2 Refer below servicenow doc, it shows that BR runs after workflows
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 12:29 AM - edited 11-29-2022 12:31 AM
Hi @Blessy2 , You should try the script below to ensure reqRecord is a valid record.
var reqRecord = current.request.getRefRecord();
if (reqRecord.isValidRecord()) {
reqRecord.requested_for = current.variables.request_for;
reqRecord.update();
}
else {
gs.info('reqRecord is not valid')
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 02:52 AM
Hi @Tuan Vu, Thanks for the response. It's not working this way too. I tried to do a log for "reqRecord.requested_for" and have seen that the sys_id of the contact is captured. The issue is "the update" is not happening.
Trying the same with Business rule (after -insert, update), still no output. On insert of the record, requested for is not updated. But on update it's working.