How to hide state option on change form?

Alex78
Tera Contributor

Hi Team, Good morning!

 

How to hide the state option on the change form?

for example: when approval is approved then show only state options like canceled, closed completed, and closed incompleted.



Alex78_0-1704114419882.png

 

Thank you!

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @Alex78 ,

 

Yes you can achieve this by using onLoad client script or if you want to filter the choices on change then you can use onChange client script as well and show the options only which you want to show based on field value.

 

You can refer the below sample script as well for better understanding.

function onLoad() {
   // Assuming 'approval' is the field representing approval status
   var approvalStatus = g_form.getValue('approval');

   // Array of state options to hide for certain approval status
   var statesToHide = ['1', '2', '3']; // Add the state values you want to hide

   // Remove options based on approval status
   if (approvalStatus === 'approved') {
      for (var i = 0; i < statesToHide.length; i++) {
         g_form.removeOption('state', statesToHide[i]);
      }
   }
}

Or else you can refer the below article as well for in detailed information about how to hide or show the choices

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

 

Thanks,

Aniket

View solution in original post

4 REPLIES 4

Rene El Hamzh
Kilo Sage

Hi @Alex78,

 

availability/visibility of states and their transitions are usually defined within the change model. You could define that in a model state transition definition. If you don't use that approach, you could use a client script and work with g_form.addOption() and g_form.removeOption().

 

Best regards,

Rene

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Alex78 ,

 

U need to use an onChange client script & the variable u need to select is approval variable.

 

Once approval variable is approved u need to remove all the other options

 

Something like 

 

if(newValue == "approved"){

g_form.removeOption("field_name","value");

}

 

Thanks,

Danish

 

Aniket Chavan
Tera Sage
Tera Sage

Hello @Alex78 ,

 

Yes you can achieve this by using onLoad client script or if you want to filter the choices on change then you can use onChange client script as well and show the options only which you want to show based on field value.

 

You can refer the below sample script as well for better understanding.

function onLoad() {
   // Assuming 'approval' is the field representing approval status
   var approvalStatus = g_form.getValue('approval');

   // Array of state options to hide for certain approval status
   var statesToHide = ['1', '2', '3']; // Add the state values you want to hide

   // Remove options based on approval status
   if (approvalStatus === 'approved') {
      for (var i = 0; i < statesToHide.length; i++) {
         g_form.removeOption('state', statesToHide[i]);
      }
   }
}

Or else you can refer the below article as well for in detailed information about how to hide or show the choices

 

Let me know your views on this and Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

 

Thanks,

Aniket

Siddhesh Gawade
Mega Sage
Mega Sage

Hello @Alex78 ,

 

You can write a simple onload client script as below. Please remeber to change appropriate field name and options to remove as per you business case.

function onLoad() {
	
    var approval = g_form.getValue('approval');
    if (approval == 'approved') {
        g_form.removeOption('state', '1');
    }

}

 

Kindly mark the answer ✔️Correct or Helpful ✔️If it addresses your concern.


Regards,

Siddhesh