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

I remove getValue and run the script same problem appears values are not captured

Vinod,

Since we are creating workflow for sc_req_item table, the workflow runs based on the insertion/updation made to this table(as far as I know).

But, we wanted to get data from sc_task table. That means, the insertion is done at sc_task table.

If I am not wrong, we need to have this Run Script activity on sc_task table and I have tried with the below code. It worked good.

-------------------------------------------------------------------

var req_item = new GlideRecord('sc_req_item');
req_item.addQuery('sys_id',current.request_item);
req_item.query();
if(req_item.next())
	{
		var inc = new GlideRecord('incident');
		inc.initialize();
		inc.short_description = current.short_description;
		inc.insert();
	}

-----------------------------------------------------------------------

Let me know how far did this help you.

Thanks

 

Hi Archana,

the following script is tested in scripts background it create incident ticket 

var task = new GlideRecord('sc_task');
task.addQuery('number','SCTASK0010167');--How to capture this number dynamically
task.addQuery('request_item',"e8a8d83bdb21d3002c885901cf9619d4");

task.query();

while(task.next())
{
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = 'hhh';
inc.insert();
}

current.number is not working

Vinos,

You should not use current.number, use current.request_item since your query is to look for the parent of sc_task which is sc_req_item.

So, use the code from the previous reply in the workflow created on sc_req_item.

Hope this helps.

Thanks