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

vinod8008
Kilo Explorer

Hi,

The field is in the sc_task table and I want to fill the short description of incident dynamically

 

 

 

Thanks.

In that case, this may help you:

var task = new GlideRecord('sc_task');
task.addQuery('request_item',current.number);
task.query();
if(task.next())
{
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = task.value_of_field1;
inc.description = task.value_of_field2;
inc.insert();
}

 

Mark the answer as Correct/Helpful based on the impact.

Thanks,

Chappidi Archana

Sorry, the code is not working.Even incident is not created.

Please modify the second line in the above code as:

task.addQuery('request_item',current.sys_id);

Mark the answer as Correct/Helpful based on the impact.

Thanks,

Chappidi Archana

Actually request_item is a reference field so update the filter statement to current.sys_id.

(i.e task.addQuery('request_item ',current.sys_id);)