How to assign table_sys_id on the attachment record on script?

Moon1
Giga Contributor

Hi, all,

On the workflow for the service catalog item, I would like to attach the attachment to the service Catalog task.

So far, I am on success to create an attachment record on the Catalog Task activity on the workflow with the following snippet of the code below.

However, when I check the attachment record on the 'sys_attachment.list', 'table_sys_id' is empty which is the reason (I think) a sc_task record generated has no Attachment.

Could anyone give me the guidance to resolve this issue?

Appreciate your help and comment in advance,

Moon 1

---

// dataJosn is the JSON string

task.u_data = dataJson;
try {
// Attach the RITM number to the file name
var fileNameAttach = 'Data_'+current.number+'.json';
var contentTypeAttach = 'application/json';
var gsAttach = new GlideSysAttachment();
var idAttached = gsAttach.write(task, fileNameAttach, contentTypeAttach, galDataString);

gs.info('>>>DEBUG: Task');
gs.info(task);
gs.info('>>>DEBUG: ID of Service Catalog Task Attachement: (' + idAttached +')');

//ToDo: Need to assign table_sys_id to the attachment when table_name is 'sc_task'. sys_attachment table has the attachment record generated.
var att = new GlideRecord('sys_attachment');
att.addQuery('sys_id', idAttached);
att.query();
if (att.next()) {
gs.info('>>>DEBUG: attachment record generated!');
att.table_sys_id = current.parent.sys_id;
att.update();
}
} catch (ex) {
gs.error('Error to create a catalog task. A reason is ' + ex);
}

9 REPLIES 9

I thought you were tying to copy an attachment that is attached at the requested item level and copy it to the task.  I'm not sure I understand your requirements to put an attachment on the task to have the values of the variables that were filled out.  That seems redundant to me.

hi, 

Thank you for a quick reply.

 

The reason to attach an attachment 'with  sc_item variables' to the sc_task is creating a service task for another user to take care of next step of the Business (requirement) process such as "downloading JSON string which contains all information from the Variables of SC item (using Portal Widget) for the next step for another user needs to handle etc.".

 

Moon 1

But the variables from an SC Item are displayed on the task.  Wouldn't that give the info that you are trying to attach?

You are right that Variables of SC Item shown on SC task, but there another user to be assigned to take SC task needs to download a information (Variables informat) in JSON or XML (we chose JSON) on their local system, and using another Application (SW) not in SNOW App, and there is another information other than Variables from SC item.

Moon 1

Moon1
Giga Contributor

With the hint from 'bricast', I achieve what I wanted to do to set attachment to sc_task with Variables from sc_item (through portal widget) using Business Rule on sc_task.

I moved my script code from workflow of sc_item to create Attachment using Variables to the Business Rule - insert and set task_sys_id after creating an attachment.

Not sure it is a proper way or not. but it works.

Lots of thanks to bricast's comment.

 

Moon 1