When using a multistate button, is it possible to hide one or two of the options based on other properties, say user role? (i.e. I want to show extra options for admin, but not for regular users)
I recommend different buttons, and using the visibility option to show or hide based on user role with a short script/expression
With the multistate button to do that I would create custom properties to store the datasets for the configurations you want to use. Then you can do an expression on the “States” property using the hasRole() expression function to switch between your datasets.
You can do the same thing with with a different type of button using visibility like @andrews said but if you want to use the multistate button you will need to swap out the states dataset to accomplish what your looking for.
Well I guess I’ll throw myself under the bus here lol.
To clarify I was not saying to use a different button. But to create multiple multistate buttons, overlay them on the window. and use visibility with hasRole() to control which button actually shows and is accessible.
I’m not very familiar with datasets this is something i have to play with more.
Ah, I misinterpreted what you meant. Personally I hate stacking objects unless I absolutely have to. I would prefer to use one object with a custom property to alter an object that accepts a dataset or other properties I need to change. You just have to recreate the same dataset that is used in the property your trying to alter but I think its cleaner in the end.
Your way sounds much better. I just don’t really know how to do that yet. But I am gonna play around with it when i have a chance.
I agree completely. I just got finished re-creating a Rsview32 project, with heavy use of stacked objects, in ignition. Though i think with older HMI that really was how you needed to do things.
@josborn Older HMI’s and SCADA’s that was the only way to do things. I’ve had to convert a number of projects. I can feel your pain with having to sort through all of it.
A client startup event script is a good place to do this.
Edit: Here is an example incase you need one. I am no expert on manipulating datasets so i leaned on client tags and copy paste. I have a client data set tag for the two multi state options, and one for the one to be applied after a user logs in. I created two multistate buttons, used the dataset editor to get them the way i wanted, then copied the dataset and pasted it into the two client tags. For the multi state indicator i want to have different options, i just bound the buttons states property to the selectedDataset tag.
There are undoubtedly better ways to do this, but this one was pretty easy for me, not having a ton of experience manipulating datasets with scripting.
roles = system.security.getRoles() paths = ['[client]adminDataset', '[client]otherDataset'] tags = system.tag.readBlocking(paths) if "Administrator" in roles: system.tag.writeBlocking(['[client]selectedDataset'], [tags]) else: system.tag.writeBlocking(['[client]selectedDataset'], [tags])
Actually @bpreston’s way is one of those better ways i mentioned. Two custom properties and an expression binding, very clean.
Don’t do this ! You’re writing the dataset to a tag, which is shared between all clients.
Here’s an example situation:
Non-admin user starts a session, and non-admin dataset gets written to a tag. Those are then used to determine whether or not the user has access to certain things. Those things are blocked for now.
Then, admin user starts a session: The admin dataset is written to the tag. Tags being gateway scoped, the first, non-admin user, gets the new dataset and gets access to restricted parts of the project.
If you want to save something on a per-user/session basis, that’s what session properties are for.
@pascal.fragnoud as I used client tags, which to my knowledge are independent for each running Client, no?
Oh, this is vision… Never mind then, I don’t know anything about vision.
What kind of tag would you save a dataset to? I pasted one into a text editor and got
"#NAMES" "value","selectedText","unselectedText","selectedBackground","unselectedBackground","selectedForeground","unselectedForeground","selectedBorder","unselectedBorder","selectedImage","unselectedImage" "#TYPES" "I","str","str","clr","clr","clr","clr","str","str","str","str" "#ROWS","3" "2","Calibrate","Calibrate","color(255,255,0,255)","color(250,250,251,255)","color(112,117,122,255)","color(112,117,122,255)",,,"","" "0","Off","Off","color(255,0,0,255)","color(250,250,251,255)","color(255,255,255,255)","color(112,117,122,255)",,,"","" "1","On","On","color(0,255,0,255)","color(250,250,251,255)","color(112,117,122,255)","color(112,117,122,255)",,,"",""
did you have to use multiple tags?
ah thank you guys. I seem to be making things way more complex than they are today. lol