cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

How to assign user group to the variable?

How to assign user group to the variable?

Hemingway
Established Member

I am going to assign the user group to some virtual variable. I've found this function in Visuals

getUserData(key [, lookupIn])

 

and trying to extract the group from current logined user:

const im = shmi.requires("visuals.session.UserManager");
        let a = im.getUserData('group');
        console.log(a);

But, I've got null as a result. What I am doing wrong, maybe someone has code example?

3 REPLIES 3

Sgilk
Contributor

@Hemingway ,

I am very confused what you are trying to do here. Why do you have a user named group?😂

The function getUserData() searches the userData and groupData properties of the current user object. As you can see here, these objects are empty on my test user in the group testGroup after initial creation. It's not clear to me if you can modify these through the WebIQ Designer somehow. The User Data fields in the User Manager don't seem to affect these properties.

Sgilk_0-1713298811349.png

If I first call setUserData() and add some properties to this object, getUserData() will return them as expected.

Sgilk_1-1713299094568.png

Sample code is below

 

        const um = shmi.requires("visuals.session.UserManager");

        um.setUserData({
            "hello": "world",
            "deleteme": null,
            "test" :1234
        });

        let a = um.getUserData('hello');
        let b = um.getUserData('test');
        console.log(a);
        console.log(b);

 

 

HmiGuide
Community Moderator
Community Moderator

Reading your text, I expect that you want to read information (e.g. language, groups) of the current user and store it in a variable, for working with it.

To find this info you need to log in to https://www.smart-hmi.com/ In "Documentation > WebIQ Developer Manuals > Web IQ Visual Reference" you find the documenation with examples. The example below prints some info of the current user to the console.

 

// get json with data of current user
const currentUser = shmi.visuals.session.UserManager.getCurrentUser();
// log info to console
console.log(`Current user is '${currentUser.name}' with configured locale '${currentUser.locale}'.`)
console.log("groups of user:")
currentUser.groupList.forEach(grpName => {
    console.log(grpName)
})
Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist