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

randrews
Tera Guru

i wouldn't do this if i were you... this copies the attachment over.. which means you now have TWO attachments <possibly more if there are more than one item on the request>.. one on the request one on the item.. if the customer updates one the tech may not see those updates..



instead what i would do is create a related list on the item table that queries the attachment table and shows attachments for the request... this way you only have ONE attachment.. I compare this to emailing a spreadsheet to five people... what you end up with are five DIFFERENT spreadsheets and no one knows which is correct.. instead keep ONE spreadsheet <or attachment> and show it where you need to .. so there is only one authoritative document to update.