CATALOG ITEM: How to make a variable mandatory and visible based on 2 conditions in client script?

Ridhima_1
Tera Contributor

Hi,

Greetings for the day!
I have a requirement where Division (String variable) should be visible and mandatory when Company (reference variable) has business area "India" and Payment type (choice variable) is "Write Off".
I have created a Catalog Client script on change of company code which is working fine if we select payment type and company (having business area as India) but when we change payment type (not Write Off) after selecting company code still it shows Division as mandatory which shouldn't be there.

CATALOG CLIENT SCRIPT:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   g_form.clearValue('division');
   var ptype = g_form.getValue('payment_type');
   var comp = g_form.getReference('company');
   if (comp.u_business_area1 == '6027edb82d334140f2f82e743652f457' && ptype == 'Customer WriteOff')
    {
        g_form.setMandatory('division', true);
        g_form.setDisplay('division', true);
    }
    else
    {
        g_form.setMandatory('division', false);
        g_form.setDisplay('division', false);
    }
}


Please assist here, Thanks in advance!

Regards

2 REPLIES 2

saivenkates5338
Tera Contributor

Hi @Ridhima_1 

you have forgotten to use callback function in getReference.

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

   var loc=g_form.getReference('location',callback);
   function callback(loc){
	var latitude=loc.latitude;
	var longitude=loc.longitude;
	g_form.setValue('latitude',latitude);
	g_form.setValue('longitude',longitude);
   }

   //Type appropriate comment here, and begin script below
   
}

 

Thanks and Regards

Sai Venkatesh

 

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Ridhima_1 

You have forgotten to use call back function in get Reference

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

   var loc=g_form.getReference('location',callback);
   function callback(loc){
	var latitude=loc.latitude;
	var longitude=loc.longitude;
	g_form.setValue('latitude',latitude);
	g_form.setValue('longitude',longitude);
   }

   //Type appropriate comment here, and begin script below
   
}

 

Thanks and Regards

Sai Venkatesh