Need to create catalog task based on variable selected

Nisha28
Tera Contributor

Hello ,

I am trying to create a catalog task using business rule, so the requirement is when  first task created through workflow when this task is closed complete one variable is editable in this task if someone select that variable as Yes the it should create the other task however I cannot acheive this through workflow as the workflow is triggered already and we have to introduce this task in middle thats why need to use business rule 

I have tried with below code but it is not working

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

// Add your code here
var gr = new GlideRecord('sc_task');
gr.initialize();
gr.request_item = current.sys_id;
var rfsTitle = current.variables.RFS_Title;
gr.short_description = "Create SOW - " + rfsTitle;
var rfsDetailedDescription = current.variables.Detailed_description_Requirement;
gr.description = rfsDetailedDescription;
;gr.insert();

})(current, previous);

 

find_real_file.png

1 ACCEPTED SOLUTION

Try to add an additional condition in the BR condition field as "current.variables.XXXXX.changes()" as mentioned here:

https://community.servicenow.com/community?id=community_question&sys_id=57f65a531bb51010305fea89bd4b...

and see if this restricts the BR on every update.

 

Edit:

It would be even better if you remove your variable condition in the condition builder and write this only in the condition field of the BR:

current.variables.XXXXX.changesTo(value);

Replace "value" with the backend name of "Yes" and XXXXX as the variable name.

Don't forget to check the "update" check box in the BR.

Give it a try.

 

Thanks.

View solution in original post

4 REPLIES 4

Sunjyot Singh
Kilo Guru

Hi,

 

I think you need to run this BR on update so check update in the BR and give it a try.

 

Thanks.

Hello Sunjyot,

 

Thanks for your reply.

For update it is working but what is happening is everytime whenever RITM record is updated it is creating as new task.

 

Try to add an additional condition in the BR condition field as "current.variables.XXXXX.changes()" as mentioned here:

https://community.servicenow.com/community?id=community_question&sys_id=57f65a531bb51010305fea89bd4b...

and see if this restricts the BR on every update.

 

Edit:

It would be even better if you remove your variable condition in the condition builder and write this only in the condition field of the BR:

current.variables.XXXXX.changesTo(value);

Replace "value" with the backend name of "Yes" and XXXXX as the variable name.

Don't forget to check the "update" check box in the BR.

Give it a try.

 

Thanks.

Hello Sunjyot,

Yes it is working correctly . Thanks for your help