- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2018 05:32 AM
I am new to service now. I Need to list all the records of a table in widget/Service portal along with the attachments if exist. I listed all the records from the table but i want to validate whether each record in a table has an attachment or not. while obtaining the resultset of records how to identify whether the attachment present in a record or not, if present how to get those attachment details.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2018 12:23 AM
Hi,
Please try below script in fix script/background script for your table.
This will give you attachment names and record number is attachment exist else it will log a statement that the current record doesn't have an attachment.
var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.query();
while (gr.next()) {
var grAttch = new GlideRecord('sys_attachment');
grAttch.addQuery('table_sys_id',gr.sys_id); // get attcahments for current incident
grAttch.query();
if(grAttch.getRowCount()>0){ //attachment exist
while(grAttch.next()){
gs.print("There is an attachment on"+gr.number+" with name : "+grAttch.file_name);
}
}
else{
gs.print("No attachments were found on "+gr.number);
}
}
Please mark it correct/helpful based on the response.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2018 12:23 AM
Hi,
Please try below script in fix script/background script for your table.
This will give you attachment names and record number is attachment exist else it will log a statement that the current record doesn't have an attachment.
var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.query();
while (gr.next()) {
var grAttch = new GlideRecord('sys_attachment');
grAttch.addQuery('table_sys_id',gr.sys_id); // get attcahments for current incident
grAttch.query();
if(grAttch.getRowCount()>0){ //attachment exist
while(grAttch.next()){
gs.print("There is an attachment on"+gr.number+" with name : "+grAttch.file_name);
}
}
else{
gs.print("No attachments were found on "+gr.number);
}
}
Please mark it correct/helpful based on the response.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2018 11:19 PM
Thanks.. worked out