How to add the file in catalog task

suuriya
Tera Contributor

Hi,

 

when the user submits the catalog request by attaching the spreadsheet/file and that file need to be added/present in catalog task...how can we do that.

 

Thanks in advance

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@suuriya You can add an onBefore Insert Business rule on Catalog Task table as follows.

Screenshot 2023-10-09 at 3.47.40 PM.pngScreenshot 2023-10-09 at 3.48.24 PM.png

Here is the script.

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(current.request.hasAttachments()){
		var attachment = new GlideSysAttachment();
		attachment.copy('sc_request',current.request.getValue('sys_id'),'sc_task',current.getValue('sys_id'));
	}

})(current, previous);

Hope this helps.

View solution in original post

3 REPLIES 3

Vishal Birajdar
Giga Sage

Hi @suuriya 

 

You can use "GlideSysAttachment()"  class & use copy() function available OOTB

 

You can do this in Catalog task (in script part ) in Workflow or flow designer :

var task_sysid = task.setNewGuidValue(); //set new GUID to task
var atta = new GlideSysAttachment();
var result = atta.copy('sc_req_item', current.getUniqueValue(), 'sc_task',task_sysid );

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

HI @Vishal Birajdar ,

 

I tried this in WF Catalog task script part but it throws an error and task is not created so i commented it and checked task created....seems some issue in script.

suuriya_0-1696923065982.png

 

Sandeep Rajput
Tera Patron
Tera Patron

@suuriya You can add an onBefore Insert Business rule on Catalog Task table as follows.

Screenshot 2023-10-09 at 3.47.40 PM.pngScreenshot 2023-10-09 at 3.48.24 PM.png

Here is the script.

 

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(current.request.hasAttachments()){
		var attachment = new GlideSysAttachment();
		attachment.copy('sc_request',current.request.getValue('sys_id'),'sc_task',current.getValue('sys_id'));
	}

})(current, previous);

Hope this helps.