Client script Help : Assignment group to be made mandatory only when Assigned to is Filled

Shree Nag
Tera Expert

Hello All,

Appreciate your help in this client script.

My requirement is to make Assignment group on a project task form mandatory, only when assigned to is filled in.

I wrote a client script for this, but find it not working when assigned to is empty.

1. When Assigned to is empty, Assignment group is empty - Able to submit.

2. When Assigned to is filled, Assignment group is empty, Error message shows up as expected.

3. When I fill in the assignment group, the Error message still shows up.

 

This is my client script. Could you please let me know what could be wrong?

 

 

function onSubmit() {
 

   //Type appropriate comment here, and begin script below
   var Assignedto=g_form.getValue('assigned_to');
    if(Assignedto=="")
        {
           
       
            return true;
           
        }else
           
            {   g_form.addErrorMessage("Please  select the assignment group");
           
            return false;
            }
   
}

 

1 ACCEPTED SOLUTION

Alp Utku
Mega Sage

You can easily write UI Policy rather than script on project task form.

 

When to run : Assigned To is not empty 

 

Then go to UI Policy Actions, find Assignment Group field, make Mandatory true and the rest leave as It is. 

View solution in original post

4 REPLIES 4

Jake Sadler
Kilo Sage

Try this:

function onSubmit() {
 

 

   //Type appropriate comment here, and begin script below
   var Assignedto=g_form.getValue('assigned_to');
var assGroup = g_formn.getValue("assignment_group");
    if(Assignedto=="" && assGroup=="")
        {
           
       
            return true;
           
        }else
           
            {   g_form.addErrorMessage("Please  select the assignment group");
           
            return false;
            }
   
}

@Shree Nag,

 

or an onChange script this this code in it:

 

if(g_form.getValue("assigned_to") != ""){

g_form.setMandatory("assignment_group",true);

}

Alp Utku
Mega Sage

You can easily write UI Policy rather than script on project task form.

 

When to run : Assigned To is not empty 

 

Then go to UI Policy Actions, find Assignment Group field, make Mandatory true and the rest leave as It is. 

_Tushar Soni
Tera Guru

Hello @Shree Nag ,

 

UI Policies --> You can achieve this scenario with just 2 steps.

Conditions: current.assigned_to != ' ';
UI Policy Actions: Check the box to make the field mandatory when the condition is met 

 

Client Script --> onChange

 

(function executeRule() {
    // Check if Assigned To field is filled
    if (g_form.getValue('assigned_to') != '') {
        // Make Assignment Group field mandatory
        g_form.setMandatory('assignment_group', true);
    } else {
        g_form.setMandatory('assignment_group', false);
    }
});

 

If you found my response helpful, please consider marking it as "Helpful" or "Accept Solution." Thank you!