Make a field Mandatory on task table based on its variables.

Deepak Shaerma
Kilo Sage

Hello community, 

We have 1 custom field named asset on sc_task table and there are some variables on the form also. My requirement is, i want to make the asset field mandatory  only when Asset type variable is eus and state changes to closed complete. 

 

Any help how to get variable value and make a proper conditions through ui policy scripts or from client script.

3 REPLIES 3

Abhay Kumar1
Giga Sage

@Deepak Shaerma Try below steps if helps you:

Create a UI Policy on the sc_task table.

 

Set the Conditions:

State is Closed Complete.

 

Use a Script condition to check the value of the variable (since variable values are not directly accessible in UI Policy conditions).

 

UI Policy Script:

// Script condition

(function() {

    var assetType = g_form.getValue('variables.asset_type'); // Replace 'asset_type' with the actual variable name

    return assetType === 'eus';

})();

 

UI Policy Action:

Set the asset field to Mandatory.

Brad Bowman
Kilo Patron
Kilo Patron

You can use a Client Script on the sc_task table.  Use any of the g_form methods, like getValue, setMandatory... specifying either the field name or a variable name - the syntax doesn't change so you can use g_form.getValue('state') and g_form.getValue('variable_name')

Following your example, it sounds like an onChange Client Script when State changes is your best bet:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

	if (newValue == 3) { //Closed Complete
		if (g_form.getValue('v_asset_type') == 'eus') { //variable name and value
			g_form.setMandatory('u_asset', true); //custom field name
		}
	}
}

Deepak Shaerma
Kilo Sage

This is helpful. Thanks @Brad Bowman