How to get current user role in JS Script shape?

  • Christian
        2 years ago #30097

        Hi all

        rather a short question, but I do not find this information in the documentation: how to get the roles of the currently logged in user in the JS Script shape in the process designer? In the code snippets, there is only “getUsername”…

        Thank you!

         

        Christopher Steinbach
            2 years ago #30101
            Up
            1
            Down
            ::

            Hi Christian,

            I don’t think that this is possible. The user API in a script shape is limited because of security reasons.

            You can solve this by using a business object to do this kind of request for your user.

            Dan
                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)
              2 years ago #30106
              Up
              1
              Down
              ::

              Hi Christian,

              you can use the methode “getCurrentUserRole” of the Server Side Business Object “ITIZ_User” which is availabe in the Simplifier standard content.
              As an input parameter you can name a role and the business object will return a boolean whether the executing user has this role or not.

              Hope this helps!

              Best regards,
              Dan

              Dan
                  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)
                2 years ago #30110
                Up
                1
                Down
                ::

                Hi Christian,

                yes you summarized it correctly.
                Inside the process designer you’d have to use this business object and save the result (true / false) as a variable.

                For the UI you want to change, you can then check if this value is true or false and print display the desired text. You can do this using condition and UI action shapes or use expression binding which could look something like this:

                {= ${variableHolder>/UserHasRoleXY} ? ‘user has role’ : ‘user does not have role’}

                Best regards,

                Dan

                Christian
                    2 years ago #30111
                    Up
                    1
                    Down
                    ::

                    Great, thank you, everything works fine now.

                    Christian
                        2 years ago #30102
                        Up
                        0
                        Down
                        ::

                        Hi C,

                        thank you for the quick answer. A client-side business object would also be fine, but also here I do not find an approach. I would need this role information to adapt the UI (change some text labels etc., no security related information is impacted).

                        Thank you!

                        Christian
                            2 years ago #30108
                            Up
                            0
                            Down
                            ::

                            Hi Dan

                            thank you for the answer. So summarized: I get the user role information only in the backend for security reasons. Thus, I have to implement a logic in the frontend that fetches this information from the backend, right?

                            Thanks and best regards

                            Christian

                          Viewing 7 posts - 1 through 7 (of 7 total)

                          You must be logged in to reply to this topic.