How to create new catalog task based on previous task variable by using Workflow

mastan babu ko1
Tera Contributor

There is a check box variable in task 1, If check box value is set to 'true' then we need to create new task from workflow.

 

1st task short desc is (verify users license)

 

 

Need help guyz?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@mastan babu ko1 

you can use IF activity in workflow with this script

Output of Yes -> Catalog Task

Output of No -> Next activity

answer = ifScript();

function ifScript(){

if(current.variables.variableName == 'true')
return 'yes';
else
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

Brian Lancaster
Tera Sage

Sound like you just need to do a if after task 1 is closed to see if that variable is set to true. If it then you create the 2nd task.

Viraj Hudlikar
Giga Sage

Hello @mastan babu ko1 

 

What have tried? Is there any challenge?

See once your task 1 is complete/incomplete/skipped just proceed ahead and check with if activity whether value of variables as required or not if yes then create task 2 else skip task 2 creation.

Give a try and let us know if still any blocker.

 

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.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@mastan babu ko1 

you can use IF activity in workflow with this script

Output of Yes -> Catalog Task

Output of No -> Next activity

answer = ifScript();

function ifScript(){

if(current.variables.variableName == 'true')
return 'yes';
else
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

But not sure but below script is always taking "No" even if previous field value is 'Yes'

 

Can any one suggest ?

 

function ifScript() {
    var taskRec = new GlideRecord('sc_task');
    taskRec.addQuery('request_item', current.sys_id);
    taskRec.addQuery('short_description', 'Verify licensed users');
    taskRec.query();
    if (taskRec.next()) {
        var rec = taskRec.variables.are_already_licensed_users;
        if (rec == 'yes') {
            return 'yes';
        } else if (rec == 'no') {
            return 'no';
        }
    }
var answer = ifScript();