Skip to content

Instantly share code, notes, and snippets.

@pmgupte
Created January 15, 2016 05:20
Show Gist options
  • Save pmgupte/df835d6cdacf0345c2bc to your computer and use it in GitHub Desktop.
Save pmgupte/df835d6cdacf0345c2bc to your computer and use it in GitHub Desktop.
Servicenow script - How to read attachment to a table record.
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_name', 'my_table'); // name of table whose record have attachment
grSysAtt.addQuery('table_sys_id', '557d2d9f4fb416406b6500f18110c71c'); // sys_id of record having attachment
grSysAtt.query();
while (grSysAtt.next()) {
var sa = new GlideSysAttachment();
var attachmentContents = sa.getContent(grSysAtt);
gs.info(attachmentContents);
}
@Avijeet07
Copy link

grSysAtt.addQuery('table_sys_id', '557d2d9f4fb416406b6500f18110c71c');

how can we dynamically get the table_sys_id for the latest attachment on attachment table?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment