Json Deserialize and Reading Value
Question
Application Type
Reactive

I am currently working on enabling and disabling write access of a form based on user role. I am thinking to return the access in json format as below. 

[{"Id":1,"FieldId":1,"RoleId":1,"IsEnable":true} - Name

,{"Id":2,"FieldId":2,"RoleId":1,"IsEnable":true} - Description

,{"Id":3,"FieldId":3,"RoleId":1,"IsEnable":true} - Date

 

Then deseriablize Json in List > filter list by each field. So if I have 10 fields in the form that require checking, there will be 10 filter like below. 

Create 10 local variable e.g. EnableName, EnableDescription and assign value based on each filter.

Is there a better way to do this?





Thanks.

- Constance

Solution

Hi Constance,

see attached oml for an alternative approach. I created a screen with form of three input fields and added a data action which returns a list of Field Labels wich should be enabled. In that data action you could query if the user is in a role and return a list of field labels accordingly.

Unfortunatly the built in client action from System ListAny is not a function so i created a client action whichs takes a field label and an access list as input. Acccess List is the result from the data action.

within the client action i execute a javascript that checks if the given field label is included in the array of access list and returns true or false.

that client action is a function which i added to the enabled fields of the form.

Hope that helps.

I have do admit that iam not good at javascript, so their might be a better approach.

Demo.oml

Thanks Stefan. We have applied similar concept using function like you suggest. 

Hi Constance,

starting first with what you already have, a JSON coming back and being serialized into a list : if the size of the list roughly corresponds with the number of fields you are interested in (i.e. the number of filters you are applying), then a better approach for performance would be to loop the list only once, and have a switch to set the right local variable.

for example, if there are 14 permissions coming back, and you have 11 fields, then you'd be filtering the list 11 times, instead of looping once.  The listFilter internally has to do some kind of looping, so looping once is faster.

If you prefer your approach because of simplicity, and assuming that only one entry in your permissions list is a match for a given field, then consider a ListIndex instead of a ListFilter, I would imagine the inner workings of that will stop as soon as it finds something, as opposed to a ListFilter that would have to go to the end.

But maybe there is a better approach possible, can you tell us more about where those rules ar gotten from, and in what form are they stored.  What is the model ? Why did you decide to use JSON ?  If it is stored in a relational database, then running a query (i.e. aggregate) with the correct filters might be the most performant and cleanest thing to do.

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.