If condition in workflow script is not working as expected

Renu9
Tera Contributor

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.

1 ACCEPTED SOLUTION

you should not use apostrophe(' ')

use this : answer.push(current.variables.new_owner)

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

View solution in original post

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Hi @Mark Roethof 

Yes I compared the values and they are coming as expected. So, that part is clear.

piyushsain
Tera Guru
Tera Guru

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)

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

Renu9
Tera Contributor

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');