Creating a Change from workflow using template AND variables

FinToy
Mega Expert

Hi guys,

After reading a couple of days Docs and this forum, I still didn't find the answer.

(link to Docs: Scripted templates)

I'm running a workflow from RITM and creating a Change ticket with a couple of change tasks. I'm using a template to create all these -- success.

However, the template is not adding the affected CI to the change ticket and I also cannot add it by passing the values from the workflow. If I don't apply the template, the values are passed successfully but together with template it seems that it's not possible. Can someone suggest a workaround?

1 ACCEPTED SOLUTION

FinToy
Mega Expert

Finally got this working. I created an event that I launch from Change Request workflow as a final task. RITM workflow then waits for this event and continues after it's launched.


View solution in original post

12 REPLIES 12

FinToy
Mega Expert

Hi krithi,

Sorry for my late reply. I resolved this the following way:

I my Request fulfillment workflow I have an activity "Run script" doing the following:

 

var change = new GlideRecord('change_request');
change.initialize();
change.applyTemplate('<template name>');
change.cmdb_ci = current.configuration_item;
change.parent = current.sys_id;
change.company = current.company;
change.insert();
if (change) {
	workflow.scratchpad.changeTicket = change.number;
	current.work_notes = 'Change ticket ' + change.number + ' created. Setting Status to Pending.';
	current.state = -5; //set State to "Pending"
}
else {
	activity.result = 'Change not created';
	current.work_notes = 'WARNING - Change not created! Do something manually?';
}

This creates the change ticket using the template. However, the template does not include the change tasks. That's why you need to modify the change workflow to understand if there is a parent ticket and if it's certain type. Then just create a new workflow to create the change tasks. This is not a huge modification to ootb change workflow. Please see the following image if it explains further.

Hi, Can you also share the script used to create the change tasks.

Change tasks are not created by a script. They are created by workflow. Workflow depends on the use case, for example in my workflow above you can see that there are separate workflows that create tasks. There's an example in ootb installation of ServiceNow, just check the workflow 'Change Request - Normal change tasks'.

Plase mark this as helpful if you see my answer useful.