onAfter Transform Script not working

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 10:25 AM
I have an onAfter transform script in which I added line of code hoping that it would help populate the Requested for name on the RITM.
So to provide a little more information - there is a Business Rule that has the following script:
The business rule script as it currently is will make sure that the correct requested_for name is right on both the ritm and the req. That is working fine; however, with this script and the transform onAfter script the job that runs that creates an Onboard ritm - the requested for name is empty. That is my dilemma. I need the requested for name to be the same on both the REQ and RITM across the board.
If I change the Business Rule script to the below then the requested for name is correct on the Onboarding ritm and req, but then the name is incorrect on the REQ on all the other forms.
// if(true){
// var user = current.variables.on_behalf_ref.getDisplayValue();
// current.request.requested_for.setDisplayValue(user);
// }
if(current.variables.on_behalf == "Yes")
{
current.u_requested_for = current.variables.on_behalf_ref; // set the custom requested for field from the on behalf variable from the variables sections.
}
else if (current.variables.requester)
{
current.u_requested_for = current.variables.requester; // set the custom requested for field from the requestor variable from the variables sections
}
else
{
current.u_requested_for = current.request.requested_for;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 10:27 AM
Hi,
line number 13 should be like this; without quotes around
target.u_requested_for = user.sys_id;
remove line number 4;
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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
09-04-2019 10:44 AM
Hi Ankur,
I should have mentioned that before. I originally did it that way and that still doesn't work. So that's why I mentioned about the Business Rule.
The business rule and this onAfter script seems to be working together some how. I need the business rule to stay as it is so that all the other forms request.requested_for doesn't get messed up.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 10:52 AM
Hi,
Is this After insert Business rule or before insert business rule?
Thanks,
Ashutosh Munot

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2019 11:11 AM
It is before Insert business rule.