ServiceNow EncodedURIComponent not working

Swapna Patiband
Tera Contributor

Hello,

Need help with generating preview link with special characters(/,%,-,/,_ etc.,) on a custom form.

Preview link is not opening when condition is having special characters.

 

Thanks,

Swapna.

7 REPLIES 7

Abhay Kumar1
Giga Sage

@Swapna Patiband To generate a preview link that works with special characters in ServiceNow, you need to URL-encode the link so that special characters are properly handled by the browser.

Encode special characters in the URL so that they do not interfere with the link generation. You can use the encodeURIComponent() if works for you.

 

Swapna Patiband
Tera Contributor

Thanks Abhay.

encodeURIComponent() is not working for all special characters like % , / , - , _ , : etc.,

@Swapna Patiband Can you pls share the code to verify.

Swapna Patiband
Tera Contributor

 

// current.u_maint = "source=ABC XYZ^ORadditional_infoLIKEABCXYZ^metic_name=ab10-0814a-a% of available disk space"
var condition = current.u_maint; 

var encodedCondition = encodedURIComponent(condition);

var almLink = gs.getProperty('glide.servlet.uri) + '/nav_to.do?uri=' + 'em_alert' + '_list.do?ysparm_query='+encodedCondition;
current.u_link = almLink ;