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.

Redirect Via UI Script

Rosy14
Kilo Sage

Under Service Portal->Theme -> JS Include -> UI Script I added the below script to redirect.

 

The redirect is working but the if condition (to check role and field value) are not working.

 

(function() {

    var role = gs.hasRole("snc_internal");
    var user = gs.getUser();
    var userGr = user.getRecord();
    if (role && (userGr.getValue("u_user_type") == "Guest") && (!userGr.getValue("u_org_id"))) {
        var url = "https:test/supplier?id=kb_article_view&sysparm_article=KB0034151";

        window.location.assign(url);
    }

})();
1 REPLY 1

Rosy14
Kilo Sage

tried this one also 

 

(function() {
function checkUserRole() {
var ga = new GlideAjax('UserRoleCheck');
ga.addParam('sysparm_name', 'checkUserRole');
ga.addParam('sysparm_role', 'snc_internal');
ga.getXMLAnswer(function(response) {
if (response === 'true') {
var url = 'https://supplierportal.asda.uk/supplier?id=kb_article_view&sysparm_article=KB0034151';
window.location.assign(url);
}
});
}

// Run the function when the script loads
checkUserRole();
})();

 

SCRIPT INclude

var RoleCheck = Class.create();
RoleCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   
    hasRole: function() {
        var role = this.getParameter('sysparm_role');
        return gs.hasRole(role) ? 'true' : 'false';
    }
});