The CreatorCon Call for Content is officially open! Get started here.

how to create a task on condition

LK11
Mega Expert

I'm a ServiceNow beginner and I'm wondering if someone could help me with this please.

I have to create a task for a particular team if the user chooses 'yes'   for a condition on the form.   Any suggestions would be great.

Thank you

1 ACCEPTED SOLUTION

Arindam Ghosh
Mega Guru

Hello,



If you want this for Service catalog then You need to do this in Workflow. Create a if block with the below condition and create task if condition is yes.



Here is the sample screenshot:


find_real_file.png


Script:


answer = ifScript();



function ifScript() {


if (current.variables.field_name == 'true') { // Update the field name with original field name


return 'yes';


}


return 'no';


}



Thanks,


Arindam


View solution in original post

13 REPLIES 13

Harsh Vardhan
Giga Patron

you can use if condition activity in your workflow and set the condition there. based on it add catalog task activity.



Condition Activities - ServiceNow Wiki


Chuck Tomasi
Tera Patron

You can do this in a couple of ways. The first one that comes to mind is a business rule. This can be triggered when the record is saved (thus recognizing the value "Yes".) Something like:



Name: Create task on Yes


Table: Your table where you are watching for the record to change to "yes"


Advanced: true


Insert: true


Update: true


When: After


Condition: current.fieldname.changesTo("yes")   // where fieldname is the field you are changing to yes


Script:



(function executeRule(current, previous /*null when async*/) {



        var newTask = new GlideRecord('task_table_name'); // change to your task table name


        newTask.newRecord();


        newTask.short_description = 'This is an auto generated task';


        // set other fields with newTask.fieldname = value; here


        newTask.insert();


        gs.addInfoMessage('New task created');



})(current, previous);



Reference:


Docs: Business Rules


Developer: Business Rules Technical Best Practices Overview


Arindam Ghosh
Mega Guru

Hello,



If you want this for Service catalog then You need to do this in Workflow. Create a if block with the below condition and create task if condition is yes.



Here is the sample screenshot:


find_real_file.png


Script:


answer = ifScript();



function ifScript() {


if (current.variables.field_name == 'true') { // Update the field name with original field name


return 'yes';


}


return 'no';


}



Thanks,


Arindam


Arindam Ghosh
Mega Guru

If I answer your question, Can you Please Mark the answer correct to remove this from unanswered list.



Thanks,


Arindam