- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 01:39 AM
We have created the variable "On Behalf of" with Type "Reference" in a catalog item. We want to link the data on this field with the field "Requested For" in RITM. So, I have written a "before insert/update" business rule on the table "sc_request" to link both the field as below
(function executeRule(current, previous /*null when async*/ ) {
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) {
current.requested_for = grRITM.variables.requested_for;
grRITM.update();
}
}
})(current, previous);
The flow designer is taking requested for's approval and sending approval. But, still it is sending approval to opened by's approver
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 02:48 AM
Hi,
Glad to know that my script worked.
If my response helped please mark it correct and helpful to close the thread.
check the requested for field on RITM is field from RITM or dot walked from REQ field?
Also in the XML requested_for field is of RITM so definitely the form field is a dot walked from REQ
so if you wish you can update that as well
(function executeRule(current, previous /*null when async*/ ) {
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('sys_id', current.sys_id);
grRITM.query();
if (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) {
grRITM.requested_for = grRITM.variables.requested_for;
grRITM.update();
var req = current.request.getRefRecord();
req.requested_for = grRITM.variables.requested_for;
req.update();
}
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 01:50 AM
Hi,
You can try updating your flow designer to trigger approval based on variable value instead of RITM field.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 01:52 AM
Hello anirban300,
if you are using flow it would be better to set the field value in the flow - use "Get catalog variables" then set field value and set approver for the approval. This way you will be sure how data flows and when/if fields have correct values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 01:53 AM
Hi,
First REQ gets created and then RITM
So your BR won't find the RITM
Why not use after insert BR on RITM table and update the requests_for?
Update script as this when you create after insert BR on RITM
(function executeRule(current, previous /*null when async*/ ) {
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('sys_id', current.sys_id);
grRITM.query();
if (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.requested_for)) {
grRITM.requested_for = grRITM.variables.requested_for;
grRITM.update();
}
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2022 01:54 AM
Hi,
how is the approval user picked in flow designer Ask for approval step?
you can use Get Catalog Variables Action
Then use the variable value from this in the Ask for Approval step and set the user for approval.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
