Clear field value based on auto populated field

Saranya2
Tera Contributor

Hi All,

-> I have 2 reference fields on incident form "incident manager" and "Managing Group". If incident manager is selected, the respective group should be populated on Managing Group field that the incident manager is a part of.

-> After Managing Group has auto populated, if anyone manually changed that group, then I need to make the "incident manager" field as empty.

-> For auto populating Managing group based on incident manager, I have written on change client script & Display BR, That is working fine.

-> But to clear field value based on manual change of Managing group. I have written, on change client script, but it is conflicting. it is always clearing the field value. can anyone please suggest.

Display BR

(function executeRule(current, previous /*null when async*/ ) {       

        var MI_manager = current.u_incident_manager;

        g_scratchpad.grp = 'false';

        var x = gs.getProperty('MI_Groups');

        var grpList = x.split(',');

        for (var i = 0; i < grpList.length; i++) {

            if (gs.getUser().getUserByID(MI_manager).isMemberOf(grpList[i].trim())) {

                g_scratchpad.grp = 'true';

               }

        }

        })(current, previous);

Onchange CS to populate group

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {

      return;

   }

   var grp = g_scratchpad.grp;

   if(grp){

        g_form.setValue('u_managing_group',grp);

 

   }

  } 

Onchange CS to clear field value if group manually changes

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {

      return;

   }

   g_form.clearValue('u_incident_manager');

  }

Thanks.

6 REPLIES 6

Suyog Aptikar
Giga Guru

@Saranya2  try below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading || newValue === '') {

      return;

   }

if(newValue  != oldValue){

   g_form.clearValue('u_incident_manager');

}

  }

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog

Hi @Suyog Aptikar ,

 

I have tried your code, it is always clearing the incident manager field value because group value is changing based on manager. So always it will match the condition old value != new value.

@Saranya2 

you can combine what @Anil Lande  had provided in my script as below:

if(newValue  != oldValue && newValue=='')

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.



Best regards

Suyog

Anil Lande
Kilo Patron

Hi,

You need make change on 2nd client script as below:

 

Onchange CS to clear field value if group manually changes

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if (isLoading ) {

      return;

   }

if(newValue===''){

   g_form.clearValue('u_incident_manager');

  }

}

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande