how to grab Request Item attachment ?

nagendra1891
Kilo Contributor

Hey guys,

  var attachment   = new GlideRecord('sys_attachment');

  attachment.addQuery('table_sys_id',current.sys_id);           // unable to find the current.sys_id

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

attachment.query();

while(attachment.next()){

  gs.addInfoMessage('inside attachment'   + attachment.table_sys_id + ''+current.sys_id);

  }

never gets into the while loop

sys_attachment table contains the information of the request table but for some reason i can not access it when the request is submited.

i am running the business rule after the request item is inserted.

when i use the rest api can find the attachment

https://########.service-now.com/api/now/attachment?table_sys_id=6d08141e0f302200d53d0dbce1050eaf

{

  "result": [

      {

          "table_sys_id": "6d08141e0f302200d53d0dbce1050eaf",

          "size_bytes": "3707",

          "download_link": "https://dev10222.service-now.com/api/now/attachment/1808941e0f302200d53d0dbce1050e81/file",

          "sys_updated_on": "2016-07-25 18:09:50",

          "sys_id": "1808941e0f302200d53d0dbce1050e81",

          "image_height": "4",

          "sys_created_on": "2016-07-25 18:09:50",

          "file_name": "Screen Shot 2016-07-21 at 8.00.27 AM.png",

          "sys_created_by": "admin",

          "compressed": "true",

          "average_image_color": "#ebebeb",

          "sys_updated_by": "admin",

          "sys_tags": "",

          "table_name": "sc_req_item",

          "image_width": "2",

          "sys_mod_count": "2",

          "content_type": "image/png",

          "size_compressed": "3599"

      }

  ]

}

any help is really appreciated.

regards

NB

30 REPLIES 30

Chuck Tomasi
Tera Patron

This could be a timing issue in that your request item is inserted, the business rule runs, and then your attachment record is updated. It could just be a few milliseconds and may not even be reproducible 100% of the time.



While I don't recommend this, you could try this in your business rule before doing the query...



gs.sleep(1000); // does not work in scoped apps


gs.sleep(1000)



did not help


Uncle Rob
Kilo Patron

What table are you running this from?   My guess is that you're trying to jam the wrong sys_id into the second statement...


attachment.addQuery('table_sys_id',current.sys_id);  




i am running this query on table sys_attachment



current.sys_id matches the   attachment.table_sys_id



verified by making a rest call to sys_attachment table



https://########.service-now.com/api/now/attachment?table_sys_id=6d08141e0f302200d53d0dbce1050eaf



table_sys_id=6d08141e0f302200d53d0dbce1050eaf             ( this id is obtained from the current.sys...