Forum

Chris Bouveret
Keymaster
    Has successfully completed the online course Introduction
    Has successfully completed the online course Intermediate (200)
    Has successfully completed the online course Advanced (300)
    Has successfully completed the online course Basics (100)
    Has successfully completed the online course Advanced (320)
    Has successfully completed the Intermediate Certification
    Has successfully completed the Advanced Certification
6 years, 8 months ago #15632
Up
0
Down
::

Hi there,

you can create a new BusinessObject with the following Method: getCurrentUserRole and this code:

var user = Simplifier.User.getCurrentUser();
output.hasRole = false;
if(user.roles) {
    if(user.roles.length) {
        Simplifier.Log.info("Roles", JSON.stringify(user.roles));
        for (var i = user.roles.length - 1; i >= 0; i--) {
            if(user.roles[i].name === input.roleName) {
                output.hasRole = true;
                break;
            }
        }
    } else {
        throw new Error("User has no Roles");
    }
} else {
    throw new Error("User has no Roles");
}

this code uses the input Parameter “roleName” as String and returns the output “hasRole” as boolean (true/false)

It is based on the Simplifier BusinessObject Server API documented here

Hope that helps