- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 02:50 AM
Hi All,
I was comparing 2 reference fields in workflow script as below.
If new_owner is not the same as the one who is requested the item. Then, new owner should receive an approval request. If not , then it has to auto approve.
This script is written in IF condition block:
var newowner = current.variables.new_owner;
var reqfor = current.variables.requested_for;
answer = ifScript();
function ifScript() {
if (newowner != reqfor) {
return 'yes';
}
return 'no';
}
Even though newowner is not same as reqfor, it is going to Yes part. But it has to go to No.
Please help me in resolving this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 03:52 AM
you should not use apostrophe(' ')
use this : answer.push(current.variables.new_owner)
Regards,
Piyush Sain

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 02:55 AM
Hi there,
Have you debugged both values? To make sure that they contain a value and the value that you would expect? So you are sure that there's not an issue on that part already.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 03:14 AM
Yes I compared the values and they are coming as expected. So, that part is clear.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 03:25 AM
Hi @Renu9
According to your script , if newowner != reqfor then it would return yes so its working fine as expected, if you want it to return no then in if use (newowner == reqfor)
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 03:50 AM
Hi @piyushsain
Yes, and now I was able to pass the if condition, now I am passing the approval via push in Approval script.
answer=[];
answer.push('current.variables.new_owner');