The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to Copy URL

chanikya
Kilo Sage

hi,

i wanna copy URL of attachments into Incident Table field u_url.

find_real_file.png

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

 

 

 

 

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

9 REPLIES 9

Mark Roethof
Tera Patron
Tera Patron

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

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 

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn