- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 02:12 AM
hi,
i wanna copy URL of attachments into Incident Table field u_url.
My scripts not working....
BR Script: Table: incident before --insert/update
var producer_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'incident');
gr.addQuery('table_sys_id', producer_id);
gr.query();
if(gr.next())
{
current.u_url=gr.location.href;
}
Or-------------------------
BR Script: Table: sys_attachment before --insert/update
var grr=new GlideRecord('incident');
grr.addQuery('sys_id',current.table_sys_id);
grr.query();
if(grr.next)
{
var hrf=location.href;
grr.u_url=hrf;
grr.update();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 02:24 AM
Or if its just a list of all sys_attachments you are after:
current.u_url_field_or_something = gs.getProperty('glide.servlet.uri') + 'sys_attachment_list.do?sysparm_query=table_sys_id=' + current.getUniqueValue();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 02:22 AM
Hi there,
What is exactly your requirement? On save of the record (insert?), setting the URL for all attachments in the read-only URL field?
Would something like below for an before insert business rule help?
var urlStr = '';
var grAttachment = new GlideRecord('sys_attachment');
grAttachment.addQuery('table_sys_id', current.getUniqueValue());
grAttachment._query();
while(grAttachment._next()) {
urlStr += gs.getProperty('glide.servlet.uri') + 'sys_attachment.do?sys_id=' + grAttachment.getUniqueValue() + '\n';
}
current.u_url_field_or_something = urlStr;
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 02:24 AM
Or if its just a list of all sys_attachments you are after:
current.u_url_field_or_something = gs.getProperty('glide.servlet.uri') + 'sys_attachment_list.do?sysparm_query=table_sys_id=' + current.getUniqueValue();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 03:02 AM
my exact requirement is:
there is one incident record with 5-attachemnts, So when incident record converted into PDF, that PDF should contain that related attachments URL so, when we click on URL in PDF directly it should be navigate record related attachments list in Attachment table...
from PDF , when we click on it it is navigating into INCIDENT RECORD, as like same requirement -when i click on URL it should be navigate to record related attachmets list

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2019 03:05 AM
Hi there,
Then my second answer will provide you with the URL. Also tested on my personal developer instance.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field