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

Hi @Harsh Vardhan  - So I am pretty close with the script below with the exception of the removal of the {} that are around the document ID.  The commented out url is an example that I can now generate, but it is failing because I need to find away to remove the brackets that are part of the string for the document ID.  Do you know how I can accomplish this?

 

function onClick(g_form) {

var documentCME_ID = g_form.getValue('filenet_document_id');

//g_form.addInfoMessage(documentCME_ID);

var url = 'https://fn5digdev.mtb.com/navigator/bookmark.jsp?desktop=BDA&repositoryId=Retail&docid=%7b' + documentCME_ID + '%7dtemplate_name=dcRetail&version=released&embedded=true';

g_form.addInfoMessage(url);

top.window.open(url, '_blank');

}

//https://fn5digdev.mtb.com/navigator/bookmark.jsp?desktop=BDA&repositoryId=Retail&docid=%7{bCAE92191-...

Hi @Annette Kitzmil : You can try with regex to remove certain char from string.

 

Updated Script: 

 

function onClick(g_form) {

var documentCME_ID = g_form.getValue('filenet_document_id');
var regex = /\{|\}/g;
var newText = documentCME_ID.replace(regex, '');

var url = 'https://fn5digdev.mtb.com/navigator/bookmark.jsp?desktop=BDA&repositoryId=Retail&docid=%7b' +newText+ '%7dtemplate_name=dcRetail&version=released&embedded=true';

g_form.addInfoMessage(url);

top.window.open(url, '_blank');

}

 Hope it will help you.

 

Thanks,

Harsh

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.