Workflow IF condition is not working.

AnandKumar1
Tera Expert

Hi Team,

I am working on a workflow part to skip the approvals based on RITM string value. Below the process.

We will create a SOW request through the sc_task. Here, i have to skip the approval based on the given value from RITM variable.

i have variable solution center (Single line text) Here based on the value i should skip the approval. If users give only "Rollouts" then approvals should be skipped in the workflow. 

The workflow is in sow module table. So i am using below script gliding the sc_req_item table and trying to set YES / NO in IF condition. But this is not working.

 

answer = ifScript();

function ifScript() {


    var gr1 = new GlideRecord('sc_req_item');
    gr1.addQuery('sys_id', requesteditem);
    gr1.query();
    if (gr1.next()) {

        var solutioncenter = gr1.variables.u_solution_center;
        gs.log('solutioncenter' + solutioncenter, 'a360879');
        if (solutioncenter == "Rollouts") {
           return 'yes';
        } 
        else {
            
            return 'no';
        }
    }
}

 

1 ACCEPTED SOLUTION

Hi,

you didn't share this info

in your script you have not defined what does the variable requesteditem holds?

are you sure it holds RITM sysId

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Harish KM
Kilo Patron
Kilo Patron

Hi in your script requesteditem is not defined any where hence the error

answer = ifScript();

function ifScript() {


    var gr1 = new GlideRecord('sc_req_item');
    gr1.addQuery('sys_id', requesteditem); //requesteditem is not defined any where hence the error
    gr1.query();
    if (gr1.next()) {

        var solutioncenter = gr1.variables.u_solution_center;
        gs.log('solutioncenter' + solutioncenter, 'a360879');
        if (solutioncenter == "Rollouts") {
           return 'yes';
        } 
        else {
            
            return 'no';
        }
    }
}

Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

in your script you have not defined what does the variable requesteditem holds?

are you sure it holds RITM sysId

Also ensure you compare with this rollouts in case user types in lower case

answer = ifScript();

function ifScript() {

    var gr1 = new GlideRecord('sc_req_item');
    gr1.addQuery('sys_id', requesteditem); // requesteditem what this holds?
    gr1.query();
    if (gr1.next()) {

        var solutioncenter = gr1.variables.u_solution_center;
        gs.log('solutioncenter' + solutioncenter, 'a360879');
        if (solutioncenter == "Rollouts" || solutioncenter == "rollouts") {
            return 'yes';
        } 
        else {

            return 'no';
        }
    }
}

Regards
Ankur

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

Hi Ankur,

Thanks for your response. Yes i checked this in background script. I can see its working, but in workflow this is always setting NO.

 

At the top of the script i have added this line. I missed to update in my 1st post. Please find the attachment.

var requesteditem = current.variables.u_ritm_no;

 

Thanks.

Hi,

you didn't share this info

in your script you have not defined what does the variable requesteditem holds?

are you sure it holds RITM sysId

Regards
Ankur

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