how to make field Mandatory if priority is downgraded from P1 or P2 by anyone on incident form.

Nirav
Tera Expert

Hi,

 

I have added a field called "u_justification_for_priority" (label: Justification for priority)  on incident form. I want it to be mandatory and visible only if someone downgrades the priority from P1 or P2.

 

priority downgrading.png

 

How do we achieve it?

I have tried Ui policy but UI policy does not seems to help as there is no option like priority changes to or there is no other option which can use. Please help. 

 

Thanks in advance.

1 ACCEPTED SOLUTION

Hi Nirav,

Please try this.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if ((isLoading) && (g_form.getValue('u_justification_for_priority') == '')) {
       g_form.setVisible('u_justification_for_priority', false);
      return ;
   }
	

   //Type appropriate comment here, and begin script below
	
	if((oldValue == 2 && newValue == 3)||(oldValue==2 && newValue==4))
		{
			g_form.setVisible('u_justification_for_priority', true);
			g_form.setMandatory('u_justification_for_priority',true);
		}
	else if(g_form.getValue('u_justification_for_priority') == '')
		{
			
			g_form.setMandatory('u_justification_for_priority',false);
			g_form.setVisible('u_justification_for_priority', false);
			
		}
   
}

Thanks,

Pooja M

View solution in original post

11 REPLIES 11

Pooja Mallikarj
Kilo Sage

Hi ,

In addition to Anurag  code ,you need to add one more line to make field visible as below.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
   if((oldValue == 1 && newValue ==2) || (oldValue ==2 && newValue == 2))
g_form.setVisible('<Your field>', true);
g_form.setMandatory('<Your field>', true);
 }

 Thanks,

Pooja M

Hi Pooja,

 

I added your script but it is also getting mandatory if I change priority from P4 to P2 or P4 to P1  (upwards) which should not be.

 

I just want it to be mandatory and visible if priority is decreased from P2 ->P3 or P3->P4. Secondly how do I hide it from incident form view currently it's visible on form.

 

script I used:

 

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

if((oldValue == 2 && newValue == 3) || (oldValue == 2 && newValue == 4))
g_form.setVisible('u_justification_for_priority', true);
g_form.setMandatory('u_justification_for_priority', true);

}

 

Thanks

Hi Nirav,

Try below code.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading) {
       g_form.setVisible('u_justification_for_priority', false);
      return ;
   }
	
	if((oldValue == 2 && newValue == 3)||(oldValue==2 && newValue==4))
		{
			g_form.setVisible('u_justification_for_priority', true);
			g_form.setMandatory('u_justification_for_priority',true);
		}
	else
		{
			
			g_form.setMandatory('u_justification_for_priority',false);
			g_form.setVisible('u_justification_for_priority', false);
			
		}
   
}

Thanks,

Pooja M

Hi Pooja,

 

The  field is getting mandatory and Visible during downgrading priority from P2-> P3 but the issue here is once data is entered to mandatory field "Justification for Priority" and once form is saved the  "Justification for Priority" remains hidden.

 

The field "Justification for Priority" should be visible once it's filled.

Hi Nirav,

Please try this.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if ((isLoading) && (g_form.getValue('u_justification_for_priority') == '')) {
       g_form.setVisible('u_justification_for_priority', false);
      return ;
   }
	

   //Type appropriate comment here, and begin script below
	
	if((oldValue == 2 && newValue == 3)||(oldValue==2 && newValue==4))
		{
			g_form.setVisible('u_justification_for_priority', true);
			g_form.setMandatory('u_justification_for_priority',true);
		}
	else if(g_form.getValue('u_justification_for_priority') == '')
		{
			
			g_form.setMandatory('u_justification_for_priority',false);
			g_form.setVisible('u_justification_for_priority', false);
			
		}
   
}

Thanks,

Pooja M