cancel
Showing results for 
Search instead for 
Did you mean: 

Read only field in workview with unityscript

FABIAN_BOTINA1
Star Contributor
Star Contributor

Hello, I would like to know if with unity script, events, javascript or some dynamic means I can make depending on the value of a field validate the other fields as read-only, it is important to mention that these fields are related by a filter.

 

I require that if my State field = History the object is blocked and does not allow editing, deleting or adding.

 

I have searched in unity script, javascript and other means but I can't identify anything that will help me with this.

Additionally, I would like to know if there is any way to prevent the options marked in red from appearing, I don't like them visually.

 

3211adf0478c40178ab782fce8c5aad3

 

 

Thank you very much for any information you can give me.

1 ACCEPTED ANSWER

Stefan_Sulea
Star Contributor
Star Contributor

Hi Fabian,

 

For this kind of task you are looking at Javascript.

I am not aware of any means to make individual fields in an embedded filter read only. 

Also I am not aware of a way to make the Open Object button dissapear.

 

Also, it does not look like your filter is editable, as it does not show the Edit button. I assume that Edit mode is not selected in the Advanced tab.

 

If you want to manipulate the buttons on the filter, you can access each button through Javascript and show/hide it.

 

If you want to make the whole embedded filter read only, you can do the following: 

 

let currentView = Screen.CurrentView;let filter = currentView.Filters('name of filter');let buttons = filter.Buttons;let btnAdd = buttons.find(b => b.Name = 'Add');let state = currentView.Fields('State'); if(state.Value == 'History') { btnAdd.Hidden = true;}

 

I would run this in the OnLoad script on the view.

 

 

View answer in original post

11 REPLIES 11

Stefan_Sulea
Star Contributor
Star Contributor

Hi Fabian,

 

For this kind of task you are looking at Javascript.

I am not aware of any means to make individual fields in an embedded filter read only. 

Also I am not aware of a way to make the Open Object button dissapear.

 

Also, it does not look like your filter is editable, as it does not show the Edit button. I assume that Edit mode is not selected in the Advanced tab.

 

If you want to manipulate the buttons on the filter, you can access each button through Javascript and show/hide it.

 

If you want to make the whole embedded filter read only, you can do the following: 

 

let currentView = Screen.CurrentView;let filter = currentView.Filters('name of filter');let buttons = filter.Buttons;let btnAdd = buttons.find(b => b.Name = 'Add');let state = currentView.Fields('State'); if(state.Value == 'History') { btnAdd.Hidden = true;}

 

I would run this in the OnLoad script on the view.

 

 

Hello Stefan , thank you very much for your help, your code helped me to hide the buttons and it helps a lot, it is not the right solution but it does help and I used it.

 

I do not have the edit button marked because the user is forced to edit in the object view and not edit inline, the problem with hiding the buttons is that the user can still navigate or go to related views and it is something that I have not discovered how to remove (I marked it in red in the image of the question) so even if I hide the buttons the user can still perform actions in the related view and controlling it with hiding code for each view is tedious.

 

so what I did was use attribute restrictions and this controls those permissions and I accompanied it with your code to hide the buttons for a cleaner view (even if the user saw them it would not allow him to perform the action).

 

Thank you very much for your help, you have saved my day.

Just did a bit of digging and for cancelling the opening of related items you can set the property CancelOpenRelatedObjects = true on the filter (filter.CancelOpenRelatedObjects = true). 

 

The documentation for Javascript can be found in the "WorkView Javascript Client Side API Documentation" chapter of the WorkView MRG, there you can find all properties and methods available.

 

Also for testing Javascript it is useful to use the console from the browser developer tools.

If you use Web Client, just press F12 in Chrome or there are similar shortcuts in other browsers. 

If you use Unity Client, you need to enable the developer console in the obunity.exe.config file by adding this key under <appSettings>:

    <!-- Enable debugging -->

<add key="enableDevTools" value="true" />

 

Then you can press Ctrl-Shift-F12 and you will get the developer console.

In the console you can test immediately what something does:

Hello Stefan

Incredible, thank you very much, I don't really use the web client but opening the console from the unity client is something that will help me a lot, I will try the code to hide but with this information you have given me all the resources to continue, thank you.