Get logged user information

Hello!

We are currently planning our HMI for an industrial application, and we would like to display different windows depending on the user logged on the FlexPendant so that operators have access to production-specific windows, maintenance has access to actuators and sensors and integrators can introduce information onto the system.

Would it be possible to obtain the name of the user logged in the FlexPendant through AppStudio code?

Thank you very much in advance.

Kind Regards,

Elena Martín.

Answers

  • yitong
    yitong
    edited August 27
    You can use to RWS API to get the logged user name by `await RWS.UAS.getUser()`

    It will return you a object data like: `[{"alias":"Default User","name":"Default User","locale":"local","application":"TPU","location":"Virtual FlexPendant"}]`
  • I made this to do it. You can adjust it completely to fit you.

    async checkLoggedInUser(componentWithUserStatus, action) {
            let loginInfo = await RWS.UAS.getUser();
            console.log("👤 Huidige gebruiker:", loginInfo);
            // || loginInfo.alias === "Default User"
            if (loginInfo.alias === "admin" || loginInfo.alias === "Admin"|| loginInfo.alias === "Default User") {
                if (action === "showHide") {
                    componentWithUserStatus.show();
                }
            }
            else {
                if (action === "showHide") {
                    componentWithUserStatus.hide();
                }
            }
        }