GlideSysAttachment.copy isn't working

Mussie
ServiceNow Employee
ServiceNow Employee

Hi Guys,

I am not sure why but GlideSysAttachment.copy isn't working for me. There is a requirement where I need to copy the attachment of a requested item into a catalog task for a specific catalog items and this isn't working. I already tried using background scripting and it isn't working either:

Type - Business Rule

Runs on - sc_task

When - after, insert

function onAfter(current, previous) {

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

  gs.log('request item sys_id ' + current.request_item);

  gs.log('catalog task sys_id ' + current.sys_id);

  var gr = new GlideRecord('sys_attachment');

  gr.addQuery ('table_sys_id', current.request_item);

  gr.addQuery ('table_name', 'sc_req_item');

  gr.query();

  if (gr.next()){

  gs.log('record found');

  GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_cat_task', current.sys_id);

  }

}

Could you please review and see if I am missing something?

Mussie

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

In other words... line 14 will be:



GlideSysAttachment.copy('sc_req_item', current.request_item, 'sc_task', current.sys_id);


View solution in original post

9 REPLIES 9

Abhinay Erra
Giga Sage

Is this in a scoped application?


bernyalvarado
Mega Sage

Hi Mussie, your error is on the name of the catalog task.



Thanks,


Berny


bernyalvarado
Mega Sage

It should be sc_task.



Thanks,


Berny


Lol, I have missed the obvious, need to stop thinking too much.