Cannot get parameter from URL in UI Page

Dat Phan
Tera Guru
var keyData = GlideSecureRandomUtil.getSecureRandomString(24);
var tokenData = GlideSecureRandomUtil.getSecureRandomString(40);
var tmpGlideEncrypter = new GlideEncrypter(keyData);
var userID = '62357984c33f21101ad0b0b78640ddda';
var encryptData = tmpGlideEncrypter.encrypt(userID  + ':' + tokenData);

var tmpURL = gs.getProperty("glide.servlet.uri") + 'nav_to.do?uri=$verifyToken.do%3Fsysparm_userId=' + userID + '%26sysparm_token=' + encodeURIComponent(encrypt);
linkVerify = '<a href="' + tmpURL + '">' + gs.getMessage('Verify') + '</a>';

When clicking on the "linkVerify" in the email, on the "$verifyToken" page, I cannot get the exact data of the variable "sysparm_token" because "encrypt" has a "+" in the data.

 

3 REPLIES 3

Maddysunil
Kilo Sage

@Dat Phan 

Maybe you're encountering issue with passing the encryptData variable as the sysparm_token parameter in the URL due to the presence of special characters such as +.

Try to encode the encryptData before appending it to the URL. One common method to encode data for URL parameters is to use the encodeURIComponent() function.

 

var keyData = GlideSecureRandomUtil.getSecureRandomString(24);
var tokenData = GlideSecureRandomUtil.getSecureRandomString(40);
var tmpGlideEncrypter = new GlideEncrypter(keyData);
var userID = '62357984c33f21101ad0b0b78640ddda';
var encryptData = tmpGlideEncrypter.encrypt(userID  + ':' + tokenData);

var encodedEncryptData = encodeURIComponent(encryptData); // Encode the encryptData variable

var tmpURL = gs.getProperty("glide.servlet.uri") + 'nav_to.do?uri=$verifyToken.do%3Fsysparm_userId=' + userID + '%26sysparm_token=' + encodedEncryptData;
var linkVerify = '<a href="' + tmpURL + '">' + gs.getMessage('Verify') + '</a>';

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

@Maddysunil I tried to encode the EncryptData in my source code.

 

var tmpURL = gs.getProperty("glide.servlet.uri") + 'nav_to.do?uri=$verifyToken.do%3Fsysparm_userId=' + userID + '%26sysparm_token=' + encodeURIComponent(encrypt);

But it still doesn't work properly. Still can't recognize the "+" sign in the encrypted string.

What does the URL look like when you navigate to the verifyToken page?

You may have to decode the URI on that page to get the correct token using decodeURI or decodeURIComponent depending upon what the URL's structure.