Conditionally Hide and Display fields on Incident state using OnChange

ralphalberti
Kilo Expert

I need to conditionally Display and Hide two fields when Incident state changes to and from Dispatched Tech.

I tried this with a UI Policy but it seems I need more than just the On Load event.

I am wondering if the following is a good starting point for an OnChange() script. I am not a javascript programmer but can usually adapt others code to do what I need.

Incident state choice

Dispatched Tech which has a value of -3

The two fields I need to Hide and Display OnChange

u_tech_eta

u_tech_confirmation_number

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

      if (isLoading) {

              return;

      }

   

      if (newValue != 'Dispatched Tech'){

              g_form.setDisplay('u_tech_eta', false);   // Tech ETA

              g_form.setDisplay('u_tech_confirmation_number', false);   // Tech Confirmation Number

      }

   

}

Ralph Alberti

11 REPLIES 11

ArunKRam
Giga Expert

Hey Ralph,



I think you will have to write 2 ui policies to achieve this. One for each field.My suggestion is to avoid coding where ever possible as it loads the system.



Arun


I'm going back to the original policy I created. I had it working almost the way I wanted.



The fields show/hide the way I want the first time I enter the form.


I can change Incident States and it behaves perfectly.



Here's my problem


I Update the form when it is in the Dispatched Tech state and the two fields are visible. Perfect.


The problem I am having is that the two fields are hidden the next time I open the form even though the Dispatched Tech state is true.



Here's what my Policy looks like


Display Tech Fields.jpg


Looks like you renamed State to Incident State, which is fine. The next time you open the form - the conditions must be false. Can you confirm that both Incident States have the correct choice?



If they do, you might try using the Add OR clause. That might cover you better. Next to the word Conditions, there is add filter condition and add or clause. I'm referring to add or clause.



So instead of


incident state is x or incident state is x



try:


Incident state is x



OR



Incident state is x


You were right. I had to create 2 policies. One to hide the fields and the other to show the fields. Works perfectly now.



Thanks.