create incident via workflow

vinod8008
Kilo Explorer

We are trying to create an incident via workflow, We have tried using the run script

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();

It is working but 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.

23 REPLIES 23

Could you elaborate your workflow.Acually the below code is correct. May be some issue is in workflow.

var task = new GlideRecord('sc_task');
task.addQuery('request_item ',current.sys_id);
task.query();
while(task.next())
{
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = task.u_my_short_description;
inc.description = task.u_my_description;
inc.insert();
}

once try with below script.

var sct = new GlideRecord('sc_task');

var gr = new GlideRecord('incident');

gr.initialize();

gr.short_description = sct.short_description;

gr.description = sct.description;

gr.insert();

 

vinod8008
Kilo Explorer

Ok, let me check the code.

Ruben Viera
Tera Contributor

Hi vinod8008,

Using the same example you provided in the question.

You can create two fields in the form or catalog item:

find_real_file.png 

And use current.variables.variable_name to get the value from the form where you are executing the workflow with the Run Script

find_real_file.png

This way you can made this assignment dynamic.

Let me know if it was helpful.