Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Opening URL for PDF files

Annette Kitzmil
Tera Guru

Hello,

I relativley new and need some direction on how I would get a pdf document being retrieved from a different system via a url to open the specific form related to the record.  Below is code I attached to a UI action button.  However, I see there are various ways to do this and I am just not sure what the best option is for opening the PDF form.  Does the code look right and/or, is there a better option to accomplish this?

 

var gsRecord;
var url = 'https://fn5digdev.mtb.com/navigator';
var desktop = 'BDA&';
var repository = 'Retail&';
var documentCME_ID = current.u_filenet_document_id;
var templateName = 'dcRetail&';
var version = 'release&';
var embedded = true;

function openURL() {
{

gsRecord = ('url' + 'desktop' + 'respository' + 'documentCME_ID' + 'templateName' + 'version' + 'embedded');

action.setRedirectURL(url);

}

}

1 ACCEPTED SOLUTION

Annette Kitzmil
Tera Guru

Hi @Harsh Vardhan  - I found that and tried what you attached for the regex for removal of the curly brackets and the curly brackets were not removed.  However, I may no longer need them removed, so I believe I am all set and appreciate all of the help.  

View solution in original post

17 REPLIES 17

Harsh Vardhan
Giga Patron

Hi @Annette Kitzmil - Your script will not work because you have passed your variable as an string also you dont need to define function :

eg: script should be something like

 

var documentCME_ID = current.u_filenet_document_id;
var url = 'https://fn5digdev.mtb.com/navigator/BDA&Retail&'+documentCME_ID+'dcRetail&release&true' ;
action.setRedirectURL(url);

  

I am assuming your url values are correct. 

 

I will give you one example, you can validate with this script and it will work. same way you can configure based on your requirement. 

 

var documentCME_ID = 'search';
var url = 'https://www.google.com/' + documentCME_ID + '?q=software';

action.setRedirectURL(url);

 

Hope it will help you.

 

Thanks,

Harsh

 

 

Thank you, this was very helpful.

 

@Annette Kitzmil  Glad it helped. 

If your queries has been solved, kindly Accept the solution and close this thread.

Hi @Harsh Vardhan 

I need a little bit more help if you don't mind.  Below is an example of the URL in red that wouldn't have the same docID that is shown in the var documentCME_ID.  So I modified the code to reflect this example I got this AM, but it still isn't opening the document.  If you see why, then please share, but if not, is there a way that I can get the URL to display to try and figure out why it is failing?

 

function onClick(g_form) {
 
    var documentCME_ID = current.u_filenet_document_id;
    var url = 'https://fn5digdev.mtb.com/navigator/bookmark.jsp?desktop=BDA&repositoryId=Retail&docid=%7b' + documentCME_ID + 'template_name=dcRetail&version=released&embedded=true';
 
 
gs.addInfoMessage('URL is ' + url);
    //action.setRedirectURL(url);
 
Thanks,