How to use "Contains" condition in the workflow if condition script.

Tamilvanan T
Tera Contributor

I have a requirement where i need to create two catalog tasks parallel on the basis of the application name.  So in the workflow I'm trying to add the if condition that contains the application name. 

Condition:

answer = ifScript();

function ifScript() {
    if (current.application_name.indexOf('OpenText') > -1) {
        return 'yes';
    }
    return 'no';
}
Am I missing out something or is there a way to achieve this. Need to know how to establish this condition in the workflow. 
 
Thank you!

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Tamilvanan T 

I believe application name is a variable on your catalog form and it's reference type

if yes then update as this

answer = ifScript();

function ifScript() {
    if (current.variables.application_name.getDisplayValue().indexOf('OpenText') > -1) {
        return 'yes';
    }
    return 'no';
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Viraj Hudlikar
Giga Sage

Hello @Tamilvanan T 

You are on right track, as code written is proper. Do let us know what is blocker? What is not working? Is there any part not working?


If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

FabricioG
Tera Contributor
Hi!
May I point out that you could return the same checking state by using ternary operator?
Something like this will do the trick:

return
current.application_name.indexOf('OpenText') > -1 ? true : false;

What do you think?

Ankur Bawiskar
Tera Patron
Tera Patron

@Tamilvanan T 

I believe application name is a variable on your catalog form and it's reference type

if yes then update as this

answer = ifScript();

function ifScript() {
    if (current.variables.application_name.getDisplayValue().indexOf('OpenText') > -1) {
        return 'yes';
    }
    return 'no';
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

It worked. Thank you!