How to Use SNC.PasswordResetUtil.generateUniqueUserToken in Scoped

rubesh_u
Tera Contributor

I am currently working on a Scoped Application. How to use the 

SNC.PasswordResetUtil.generateUniqueUserToken in my scoped application. It says "SNC" not found. I just want to create that user token. How to achieve this in Scoped Application ?
2 ACCEPTED SOLUTIONS

Chaitanya ILCR
Kilo Patron

Hi @rubesh_u ,

 

you can have the code in a global script include with access from all application scopes and call that script include method in your scoped application

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

@rubesh_u 

Even if it's store app you can always supply global scope update set after customer installs/buys that app.

I have followed similar steps earlier and it's completely fine.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Chaitanya ILCR
Kilo Patron

Hi @rubesh_u ,

 

you can have the code in a global script include with access from all application scopes and call that script include method in your scoped application

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

We are building this app for Store so global script include is not captured as a applicaiton artifact any other way around ? 

Ankur Bawiskar
Tera Patron
Tera Patron

@rubesh_u 

You cannot use that in scoped app

what's your business requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

When the user resets the password and clicks submit. I need to redirect the user to a specified record page in portal.

 

I am using the Plugin : com.snc.external_user_self_registration. 
Migrating few things from this plugin. 

Copied the subflow in my scope : 

External User Onboarding

but redirection happens inside the action:

(function execute(inputs, outputs) {
var pwdUtil = new ExternalUserRegistrationUtil();
var result = this.newItem("result");
pwdUtil.sendResetEmail(inputs.user, inputs.password_reset_request, result, inputs.profile);
})(inputs, outputs);
 
 
Copied Script Include that Came from plugin :
sendResetEmail: function(userId, requestId, result, profileId) {
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', userId);
usr.addQuery('active', 'true');
usr.query();
if (!usr.next()) {
gs.info("User : " + userId + " is either inactive or doesn't exist on the instance");
return false; // just return boolean
}

var resetPasswordURL = '';
var token = SNC.PasswordResetUtil.generateUniqueUserToken(usr.sys_id);

var portalGR = this.getPortalGR(profileId);

var portalSuffix = portalGR.url_suffix;
var encodedURL = portalSuffix;
var homepage = portalGR.homepage;
if (GlideStringUtil.notNil(homepage)) {
var redirectURL = portalSuffix + "?id=" + homepage;
encodedURL = GlideStringUtil.urlEncode(redirectURL);
}

if (GlideStringUtil.nil(token)) {
this.logError("Failed to generate unique token for user. Password reset failed for user : " + usr.user_name);
return false;
}

resetPasswordURL = this.getInstanceURL() + '/passwordreset.do?sysparm_id=' + usr.sys_id +
'&sysparm_request_id=' + requestId +
'&sysparm_nostack=true&sysparm_token=' + token;
resetPasswordURL += '&sysparm_redirect_url=' + encodedURL;

var eventName = 'external.user.password.reset';
var hours = GlideProperties.get("glide.pwd_reset.onetime.token.validity", "1");

var param2 = {
hours: hours,
title: portalGR.getValue("title"),
resetPwdURL: resetPasswordURL
};

var json = new JSON();
var jsonStr = json.encode(param2);
gs.eventQueue(eventName, usr, usr.email, jsonStr);

return true;
},