creating an incident via workflow

steve_young
Kilo Expert

We are trying to create an incident via workflow and when we do, there are a lot of workflows kicked off in the workflow contexts and no incident is created.   We are on Helsinki.

We have tried using the run script activity and the create task activity and both end up doing the same thing.

This is one of the scripts we have tried via the run script activity:

(we found this via the community)

var gr = new GlideRecord('incident');

gr.initialize();

gr.short_description = 'Printer is broken again';

gr.description = 'There is something wrong with the printer again, should we get a new one?';

gr.insert();

No incident is ever created and there are a bunch of "executing" workflows showing up in the workflow contexts after we run the workflow.

Would anyone have any idea as to what is happening and what we are doing wrong?

Thanks!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Steve,



Can you provide some details about what you are trying to do or what the underlying requirement is?



Also try with the below updated script and let me know.



var gr = new GlideRecord('incident');


gr.initialize();


gr.short_description = 'Printer is broken again';


gr.description = 'There is something wrong with the printer again, should we get a new one?';


gr.setWorkflow(false);


gr.insert();


View solution in original post

4 REPLIES 4

nishailame
ServiceNow Employee
ServiceNow Employee

Hi Steve,



Script looks ok. You need to check -


- Are executing workflows on "incident" table?


- if yes, in wf_context table, every running context has related record if its on any table but global. Check which record its is associated with.


Try setting workflow to false (this will turn off the engine and won't trigger any workflow on this insert):



    var gr = new GlideRecord('incident');


    gr.initialize();


    gr.setWorkflow('false');


    gr.short_description = 'Printer is broken again';


    gr.description = 'There is something wrong with the printer again, should we get a new one?';


    gr.insert();



Also, you can try running your scripts in "Scripts - Background" to test the correctness and impact.



Thanks.



PS: Hit like, Helpful, Endorse or Correct depending on the impact of the response


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Steve,



Can you provide some details about what you are trying to do or what the underlying requirement is?



Also try with the below updated script and let me know.



var gr = new GlideRecord('incident');


gr.initialize();


gr.short_description = 'Printer is broken again';


gr.description = 'There is something wrong with the printer again, should we get a new one?';


gr.setWorkflow(false);


gr.insert();


Sai Anna
ServiceNow Employee
ServiceNow Employee

Hello ,


above comments should answer your question, I will also add reference to current item as parent to newly created Incident (if it is being called from Request item) .



var gr = new GlideRecord('incident');


gr.initialize();


gr.short_description = 'Printer is broken again';


gr.description = 'There is something wrong with the printer again, should we get a new one?';


gr.parent=current.getUniqueValue(); // Attaches incident to Request item helps in tracking


gr.setWorkflow(false);


gr.insert();



Thanks,


Sai


vinod8008
Kilo Explorer

gr.short_description = 'Printer is broken again';

gr.description = 'There is something wrong with the printer again, should we get a new one?';

How to make the short description and description as dynamic in above script.I create two fields on the sc_task table and how to capture the fields values and set the values to the description and the short description of the incident table while creating a ticket using workflow.

   please help me to achieve that task.

  ThankQ.