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

I'm still not clear. Are you looking to get all attachments on the current sc_req_item record, only one attachment?


i trying to get all the attachment for the current service catalog request raised by the user .




running a Business rule( on sc_req_item table )   every time user raises a service catalog request and trying to grab the attachment if any attached .


Thank you for the clarification Nagendra. I'm at the limit of what I can effectively do via the community.



If nobody else jumps in on this thread, you may want to consult with professional services from ServiceNow or one of our terrific partners.



Thank you for your understanding.


Does your business rule currently log out the expected current.sys_id?



Also, I notice you use attachment.addQuery('table_name',   current.getTable());  


I believe the proper syntax would be getTableName()


... but I'm not even sure if you need to query on the table name if you have the expected table_sys_id


yes i have the proper   current.sys_id



getTableName()       ( both return the same sc_req_item )


yes below query is not required.   useing it should not cause a problem too ( tried all possible combinations )


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



problem here is at the point when the query is made the data is still not present in the sys_attachment.


same query with older sys_id grabs the the attachment properly.



i want to grab the current attachment ( i am running the   business rule after the insert of request item )