How to add attachment as a link in an error message.

sreeshsurendran
Tera Guru

How to add attachment as a link in an error message, when the attachment variable is empty for a catalog item.

 

Sample screenshot attached for reference.

 

 

 

sreeshsurendran_0-1683292826330.png

 

2 ACCEPTED SOLUTIONS

Voona Rohila
Kilo Patron
Kilo Patron

Hi @sreeshsurendran 

Try this

 

var link = '<a href="/nav_to.do?uri=sys_attachment.do?sys_id=6dc35515db74bf00db9b9875db9619f2">Download Template</a>'; //replace the sys_id with actual template attachment record sysid.
var message = gs.getMessage('add your message here') + ' ' + link + ' ';
gs.addInfoMessage(message); //you can use addInfoMessage or addErrorMessage accordingly.

 

if you want to open the template in new tab and download then use this 

var link = '<a href="/nav_to.do?uri=sys_attachment.do?sys_id=6dc35515db74bf00db9b9875db9619f2" target = "_blank">Download Template</a>'; //replace the sys_id with actual template attachment record sysid.

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

Hi @Voona Rohila,

 

Made some minor changes to your code and attached the same below. Thanks for your support. 🙂

 

function onCondition() {
    var link = '<a href="/nav_to.do?uri=sys_attachment.do?sys_id=2981a87647222110dc3b690cd36d4325">Download Template</a>'; 
    g_form.addErrorMessage('Please attach before submitting :' +' ' + link + ' ');


}

View solution in original post

3 REPLIES 3

Voona Rohila
Kilo Patron
Kilo Patron

Hi @sreeshsurendran 

Try this

 

var link = '<a href="/nav_to.do?uri=sys_attachment.do?sys_id=6dc35515db74bf00db9b9875db9619f2">Download Template</a>'; //replace the sys_id with actual template attachment record sysid.
var message = gs.getMessage('add your message here') + ' ' + link + ' ';
gs.addInfoMessage(message); //you can use addInfoMessage or addErrorMessage accordingly.

 

if you want to open the template in new tab and download then use this 

var link = '<a href="/nav_to.do?uri=sys_attachment.do?sys_id=6dc35515db74bf00db9b9875db9619f2" target = "_blank">Download Template</a>'; //replace the sys_id with actual template attachment record sysid.

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Hi @Voona Rohila,

 

Made some minor changes to your code and attached the same below. Thanks for your support. 🙂

 

function onCondition() {
    var link = '<a href="/nav_to.do?uri=sys_attachment.do?sys_id=2981a87647222110dc3b690cd36d4325">Download Template</a>'; 
    g_form.addErrorMessage('Please attach before submitting :' +' ' + link + ' ');


}

Hi @sreeshsurendran 

My solution was to provide the logic so that you can use the same in your code according to your requirements. Can you please mark my response as correct.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP