create change task using Business rule

Priyanka Mathur
Tera Contributor

Hi ServiceNow Experts,

My requirement is to create a change task, when the change request short description contains "Planned Outage". I have written the below script. Can you please help me with this, as change task is not being triggered. 

createTask();

function createTask() {
var org = current.u_organization;
var groupName = '';
if (org == 'IT') {
groupName = 'IT-Network Operations';
var cTask = new GlideRecord('change_task');
cTask.initialize();
cTask.short_description = 'Change task should have test and verify';
// cTask.description = '';
cTask.parent = current.sys_id;
cTask.change_request = current.sys_id;
cTask.cmdb_ci = current.cmdb_ci;
cTask.u_predecessor = 'No';
cTask.assignment_group.setDisplayValue(groupName);
}
}

1 ACCEPTED SOLUTION

Not applicable

@Priyanka Mathur 

Can you try this:

createTask();

function createTask() {
var org = current.u_organization;
var groupName = '';
if (org == 'IT') {
groupName = 'IT-Network Operations';
var cTask = new GlideRecord('change_task');
cTask.initialize();
cTask.short_description = 'Change task should have test and verify';
// cTask.description = '';
cTask.parent = current.sys_id;
cTask.change_request = current.sys_id;
cTask.cmdb_ci = current.cmdb_ci;
cTask.u_predecessor = 'No';
cTask.assignment_group.setDisplayValue(groupName);

cTask.insert();
}
}

View solution in original post

5 REPLIES 5

Sravani44
Tera Contributor

Hi Priyanka,

 

Could you add logs to your Business Rule and check if BR is triggering or not.. Also check what does logs show.

Mark my Response as Correct or Helpful, if you find it Appropriate.

 

Regards,

Sravani

Not applicable

@Priyanka Mathur 

Can you try this:

createTask();

function createTask() {
var org = current.u_organization;
var groupName = '';
if (org == 'IT') {
groupName = 'IT-Network Operations';
var cTask = new GlideRecord('change_task');
cTask.initialize();
cTask.short_description = 'Change task should have test and verify';
// cTask.description = '';
cTask.parent = current.sys_id;
cTask.change_request = current.sys_id;
cTask.cmdb_ci = current.cmdb_ci;
cTask.u_predecessor = 'No';
cTask.assignment_group.setDisplayValue(groupName);

cTask.insert();
}
}

Hi Murthy,

I added cTask.inser(); still task isn't appearing. 

Regards,
Priyanka

Not applicable

Ok

Have you added logs? and when do you want to create a change task? right after creation of the change request?

If yes use after insert BR and try

Hope it helps

 

Thanks

Murthy