Conditional mandatory field support

PK14
Kilo Guru
Hi Team,

I'm working on the Change module and have a requirement where the Assigned to field on the Change Task should behave as follows:
It should be mandatory for all states when the Organization (from the parent Change Request) is ABC.It should be mandatory only when the state is 'Closed Complete' or 'Skipped' if the Organization is XYZ.

Please note that the Organization field (u_organization) resides on the parent table Change Request, not on the Change Task itself. I’ve implemented the following onLoad client script, but it's not working as expected. Could you please help review and suggest any corrections?

(function onLoad() {
  g_form.getReference('change_request', function(parent) {
    if (parent) {
      var org = (parent.u_organization || '').toString().trim();
      enforceAssignedToMandatory(org);
    }
  });  g_form.onChange('state', function(control, oldValue, newValue, isLoading) {
    if (!isLoading) {
      g_form.getReference('change_request', function(parent) {
        if (parent) {
          var org = (parent.u_organization || '').toString().trim();
          enforceAssignedToMandatory(org);
        }
      });
    }
  });  function enforceAssignedToMandatory(org) {
    var state = g_form.getValue('state');
    console.log('Org:', org, 'State:', state); // Debugging  
  if (org === 'ABC') {

      g_form.setMandatory('assigned_to', true);
    } else if (org === 'XYZ') {
      if (state === '3' || state === '4') { // Closed Complete or Skipped
        g_form.setMandatory('assigned_to', true);
      } else {
        g_form.setMandatory('assigned_to', false);
      }
    } else {
      g_form.setMandatory('assigned_to', false);
    }
  }
})();

Looking forward to your suggestions.
5 REPLIES 5

Sruthi17
Kilo Sage

Hi @PK14 ,

 

Please create a UI Policy with the conditions as shown below

Sruthi17_0-1753203198243.png
Create a UI Action - to make Assigned To mandatory

Sruthi17_1-1753203249045.png



I believe this should solve your problem.

 

If my response helped please mark it correct or helpful 🙂