Based on Currency field type populate user in reference field

suresh40
Tera Contributor

Hi All,

 

I Have requirement based on Proposed Gross sales field (currency type) we have to populate users in field. I have written script but is not working . Please help me on this 

 

If Proposed Gross sales  is value is 100,000 t0 999,999.99 populate user is Dir.FP&A  reference field 

If Proposed Gross sales  is value is 100,0000 t0 199,999.99 populate user is CDO,CCO,CSO reference field 

If Proposed Gross sales  is value is 2m populate user is President reference field 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
 var SBU = g_form.getValue('u_sbus');
    var values = '';
 
 
    if ((newValue >= 100,000 && newValue <= 999,999.99) && (SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' || SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' || SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' || SBU == 'product_management'))
        g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd');                  
 
    else if (values == '')
        g_form.clearValue('u_dir_fp_a')
 
 
    if ((newValue >= 1,000,000 && newValue <= 1,999,999.99) && (SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' || SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' || SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' || SBU == 'product_management'))
        g_form.setValue('u_vp_of_finance', 'bf973bdb1ba980107d28a8ecbc4bcb7f') ||             
        g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd');                  
 
 
    else if (values == '')
        g_form.clearValue('u_vp_of_finance');
 
    if ((newValue >= 1,000,000 && newValue <= 1,999,999.99) && (SBU == 'online_other' || SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'product_management'))
        g_form.setValue('u_cdo_cco_cso', 'fdc5fbdbdbe14050230aed384b961916') ||               
        g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd');                     
 
 
    else if (newValue == '')
        g_form.clearValue('u_cdo_cco_cso','');
 
 
    if ((newValue >= 2,000,000) && (SBU == 'home_depot' || SBU == 'lowes/industrial/growers' || SBU == 'building' || SBU == 'intl_ca' || SBU == 'intl_row' || SBU == 'msh' || SBU == 'online_other' || SBU == 'closetmaid_com' || SBU == 'retail_com' || SBU == 'closetmaid_com' || SBU == 'product_management')){
        g_form.setValue('u_president', 'f7973bdb1ba980107d28a8ecbc4bcb73') ||                   
        g_form.setValue('u_vp_of_finance', 'bf973bdb1ba980107d28a8ecbc4bcb7f') ||               
       // g_form.setValue('u_cdo_cco_cso', 'fdc5fbdbdbe14050230aed384b961916') ||               
        g_form.setValue('u_dir_fp_a', 'f648abdfdba14050230aed384b9619bd')                       
 
}
    else if (newValue == ''){
        g_form.clearValue('u_president','');
 
 
}
    //Type appropriate comment here, and begin script below
 
 
 
}   

 

 

1 REPLY 1

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @suresh40 ,

please try using else if instead of the if you used 2nd,3rd and 4th time OR use else instead of else if.

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.