Create Child Task

SHAIK18
Mega Contributor

Hi,

How can we achieve code for the below requirement 

Create Child Tasks (Run Script – Type) 

 Create task function – Use Script Include here and pass the RITM number as parameter to script include.

 Create a catalog task to this RITM as parent.

 Tasks Fields to be mapped

 Request Item – RITM number

Task requested for – RITM requested for

Task Short description – RITM Short Description

Task Description – RITM Description

Task State -- Open

1 ACCEPTED SOLUTION

@SHAIK

Just to inform sc_task table doesn't have requested_for field. RITM table also doesn't have requested_for.

requested_for is present on sc_request table

Refer sample script below

I am passing the current object i.e. RITM object so that you can easily dot walk in script include function and get the values and set on sc task

Script Include:

var CreateTasks = Class.create();
CreateTasks.prototype = {
    initialize: function() {
    },

	createTaskFromWorkflow: function(ritmObj){
		
		var scTask = new GlideRecord('sc_task');
		scTask.initialize();
		scTask.request_item = ritmObj.sys_id;
		scTask.short_description = ritmObj.short_description;
		scTask.description = ritmObj.description;
		scTask.request = ritm.request;
		//scTask.requested_for = ritmObj.request.requested_for; // if you are using custom field on sc_task then use that here
		scTask.insert();
		
	},
	
    type: 'CreateTasks'
};

How to call from workflow run script

new CreateTasks().createTaskFromWorkflow(current);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi - You can build a flow to automate this process. No script required.

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/administer/flow-designer/concept/f...

SHAIK18
Mega Contributor

Hi,

 

We are using workflows 

@SHAIK

Just to inform sc_task table doesn't have requested_for field. RITM table also doesn't have requested_for.

requested_for is present on sc_request table

Refer sample script below

I am passing the current object i.e. RITM object so that you can easily dot walk in script include function and get the values and set on sc task

Script Include:

var CreateTasks = Class.create();
CreateTasks.prototype = {
    initialize: function() {
    },

	createTaskFromWorkflow: function(ritmObj){
		
		var scTask = new GlideRecord('sc_task');
		scTask.initialize();
		scTask.request_item = ritmObj.sys_id;
		scTask.short_description = ritmObj.short_description;
		scTask.description = ritmObj.description;
		scTask.request = ritm.request;
		//scTask.requested_for = ritmObj.request.requested_for; // if you are using custom field on sc_task then use that here
		scTask.insert();
		
	},
	
    type: 'CreateTasks'
};

How to call from workflow run script

new CreateTasks().createTaskFromWorkflow(current);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@SHAIK

Thanks for marking my response as helpful.

Let me know if I have answered your question.

If so, please mark my response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader