Create a catalog task when a catalog item variable is selected

consuelo
Kilo Explorer

Can anyone provide information on how I would create a catalog task when a catalog item variable is selected? We do not want to modify our workflow.  

Ex: Currently, if a customer requests hardware and selects it is a replacement, two tasks are generated.   One is assigned to a group to allocate and assign the hardware and the other task is assigned to a group to configure and deliver.   We would like a 3rd task to be generated to collect the old hardware if replacement is selected.

1 ACCEPTED SOLUTION

shane_davis
Tera Expert

Below is a business rule to create a Catalog Task when the associate selects the Replacement option on the Desktop or Laptop catalog item.   The task is not created until after the request is approved. It also puts the computer name they are replacing (variable "computer_to_replace") into the short description and assigns the task to the Asset Management group.




Business Rule...



Name: Create Task - Replacement Hardware


Table: Requested Item [sc_req_item]


Active: true


Advanced: true



WHEN TO RUN.....


When: After


Order: 100


Insert: true


Update: true


Conditions: Item IS Laptop Computer -OR- Desktop Computer -AND- Request.Approval IS Approved



ADVANCED.....


Condition: blank


Script:



function onAfter (current,previous) {


//This function will be automatically called when this rule is processed.


createTasks();



// Start creating the Task to Collect IT Equipment


function createTasks() {


// Verify the Replacement option is chosen in the catalog item


var replace = current.variables.replacement;



// Get the computer name from the variable


var computer = current.variables.computer_to_replace;



// If it is a Replacement, go to the Catalog Task table [sc_task] and create the Task with this information.


if (replace == 'Replacement') {


var newtask1 = new GlideRecord('sc_task');


newtask1.initialize();


// Line below binds the RITM to the Task being created.


newtask1.request_item = current.sys_id;


newtask1.short_description = 'Collect old IT equipment - ' + computer;


newtask1.assignment_group = '8b61cf5f0a0a3c44007e37077628e90f'; // Asset Management : SYSID from Groups module


newtask1.insert();


}


}


}


View solution in original post

7 REPLIES 7

manikorada
ServiceNow Employee
ServiceNow Employee

Then you can have a business rule which will create a Catalog Task if RITM is from your required Catalog Item


Ravi Prasad1
Tera Guru

Creating after insert business rule on RITM table will give you the solution for this. In the business rule query the catalog task table and insert the record.


shane_davis
Tera Expert

Below is a business rule to create a Catalog Task when the associate selects the Replacement option on the Desktop or Laptop catalog item.   The task is not created until after the request is approved. It also puts the computer name they are replacing (variable "computer_to_replace") into the short description and assigns the task to the Asset Management group.




Business Rule...



Name: Create Task - Replacement Hardware


Table: Requested Item [sc_req_item]


Active: true


Advanced: true



WHEN TO RUN.....


When: After


Order: 100


Insert: true


Update: true


Conditions: Item IS Laptop Computer -OR- Desktop Computer -AND- Request.Approval IS Approved



ADVANCED.....


Condition: blank


Script:



function onAfter (current,previous) {


//This function will be automatically called when this rule is processed.


createTasks();



// Start creating the Task to Collect IT Equipment


function createTasks() {


// Verify the Replacement option is chosen in the catalog item


var replace = current.variables.replacement;



// Get the computer name from the variable


var computer = current.variables.computer_to_replace;



// If it is a Replacement, go to the Catalog Task table [sc_task] and create the Task with this information.


if (replace == 'Replacement') {


var newtask1 = new GlideRecord('sc_task');


newtask1.initialize();


// Line below binds the RITM to the Task being created.


newtask1.request_item = current.sys_id;


newtask1.short_description = 'Collect old IT equipment - ' + computer;


newtask1.assignment_group = '8b61cf5f0a0a3c44007e37077628e90f'; // Asset Management : SYSID from Groups module


newtask1.insert();


}


}


}