How to write if condition in workflow

spandana kalla
Tera Contributor

Hello Community,

There is a maintain item named as 'Purchase Requisition Request (IT Use Only)' with 2 variables one variable is is_this_for_software_hardware_or_labor with dropdown options as software, hardware, GBS, services and another variable(check box) is is_software_included_in_this_purchase , here if user selects hardware , GBS, services then this software included variable should get populated , I have done these in UI policies and actions and tested it its working fine . Now if user selects other than software and checked the box of software included purchase variable then it should take yes part in workflow in that way we should write logic in if condition . please help me with this 

@Ankur Bawiskar 

Thank you.

1 ACCEPTED SOLUTION

Hi,

are you sure you are comparing correct value for software

Update as this

answer = ifScript(); // add this line if you have not added

function ifScript() {
    if (current.variables.is_this_for_software_hardware_or_labor == 'software') {
        return 'yes';
    }
    if (current.variables.is_this_for_software_hardware_or_labor != "software" && current.variables.is_software_included_in_this_purchase.toString() == 'true')
        return 'yes';
    else
        return 'no';

}

Regards
Ankur

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

View solution in original post

13 REPLIES 13

Hello Mohith , 

My question is if they selects software that software included variable check box will not get populated , if they selects other than software then only that software included variable will get populated , so for first if condition the check box variable will not get populated , only other than software that particular variable will get populated . here for both if conditions it should take yes part in the workflow. Can i write in this way @Mohith Devatte 

Script:

function ifScript() {
    if (current.variables.is_this_for_software_hardware_or_labor == 'Software') {
        return 'yes';
    }
    if (current.variables.is_this_for_software_hardware_or_labor != "software" && current.variables.is_software_included_in_this_purchase.toString() == 'true')
        return 'yes';
    else
        return 'no';

}

Thanks,

After giving this script in IF condition , i tested by selecting software and other than software its taking yes part only .

 

Hi,

are you sure you are comparing correct value for software

Update as this

answer = ifScript(); // add this line if you have not added

function ifScript() {
    if (current.variables.is_this_for_software_hardware_or_labor == 'software') {
        return 'yes';
    }
    if (current.variables.is_this_for_software_hardware_or_labor != "software" && current.variables.is_software_included_in_this_purchase.toString() == 'true')
        return 'yes';
    else
        return 'no';

}

Regards
Ankur

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

Hello Ankur,

Can you please say why we use toString() in line 7 . @Ankur Bawiskar 

Regards

Because it's always safe when you compare with true or false

 

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