onAfter Transform Script not working

Cupcake
Mega Guru

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.

find_real_file.png

So to provide a little more information - there is a Business Rule that has the following script:

find_real_file.png

 

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;
}

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

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

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

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

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


Is this After insert Business rule or before insert business rule?

Thanks,
Ashutosh Munot

It is before Insert business rule.