Not able to clear the field value which is readonly and dependent on reference field

Sravani36
Tera Expert

Hi not able to clear the value of string field which is dependent on Reference field. on change of user name it's working, but if the reference field is empty it's not working.

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

   
    var caller = g_form.getReference('first_user_name', doAlert); 
    function doAlert(caller) {
    var a=    g_form.setValue('user_id',caller.user_name);
        //alert(a);
        var b = caller.user_name.split('@');
        //alert(b);
        g_form.setValue('selected_user_names',b[0]);
        

        }
    
    if(newValue==''){
        g_form.clearValue('user_id');
    
    }
    
   
}

I need to clear the user id once the Reference field (first_user_name) is empty but the above script is not working.

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello

Can you write your   g_form.clearValue('user_id'); line in below loop and remove from the last of the script

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

g_form.clearValue('user_id');
      return;
   }

Please try this and if it works mark my answer correct
    

View solution in original post

3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

Hello

Can you write your   g_form.clearValue('user_id'); line in below loop and remove from the last of the script

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

g_form.clearValue('user_id');
      return;
   }

Please try this and if it works mark my answer correct
    

Aman Kumar S
Kilo Patron

Update your code as:

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

if(newValue == ''){
     g_form.clearValue('user_id');
}
else{

 var caller = g_form.getReference('first_user_name', doAlert); 
    function doAlert(caller) {
    var a=    g_form.setValue('user_id',caller.user_name);
        //alert(a);
        var b = caller.user_name.split('@');
        //alert(b);
        g_form.setValue('selected_user_names',b[0]);
}
}

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

 

Best Regards
Aman Kumar

SumanthDosapati
Mega Sage
Mega Sage

Hi,

Move the below loop before the "var caller = g_form.getReference('first_user_name', doAlert); " line

 if(newValue==''){
        g_form.clearValue('user_id');
    
    }