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

The table_sys_id field tells you what record in sc_req_item the file is attached to, not the sys_id of the sys_attachment record.


See image below...



find_real_file.png



the sys_id of the sys_attachment record shown is: 2b6644b15f1021001c9b2572f2b47763


    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();




running this query


is this wrong ?


If this is from a business rule running on the sys_attachment table, then yes. You don't know which request item you are looking for.



What is it this business rule is supposed to be doing? If you run the business rule on the sc_req_item table, then the query becomes



var attachment   = new GlideRecord('sys_attachment');


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


  attachment.addQuery('table_name',   current.getTable());


  attachment.query();


i am running a business rule on request item table ( sc_req_item) on insert



and trying to grab the attachment when the user raise a service catalog request




this query is running on same business rule.


var attachment   = new GlideRecord('sys_attachment');


  attachment.addQuery('table_sys_id',current.sys_id);       // if i remove this statement it gets al the previous attachment records


  attachment.addQuery('table_name',   current.getTable());


  attachment.query();