You are viewing limited content. For full access, please sign in.

Question

Question

Lookup table field return "Undefined" value

asked on April 19, 2018

Hi,

I have a field in table which being filled by lookup. However, when i tried to call that field as a variable from Javascript I get "undefined" even though there is value in that field. I suspect that it was because of the timing issue so i added a timeout function but it's still return undefined.

This is my code

$('table.Table1').on('change','.Field1 input',function() {  
 
         $('.fundtable tbody tr').each(function(){
           $(this).find('.autofill').trigger('click'); -- Autofill to trigger look up to field 2
setTimeout(function (){ 
var field2value = $(this).('.field2 input').val();
           
         

          alert(field2value);
          
    	},500);
    });
   
  });
  

Any helps are appreciated.

Thank you

0 0

Replies

replied on April 20, 2018 Show version history
$('table.Table1').on('change','.Field1 input',function() {  
 
         $('.fundtable tbody tr').each(function(){
           $(this).find('.autofill').trigger('click'); -- Autofill to trigger look up to field 2
                setTimeout(function (){ 

                    var field2value = 0;
                      
                    field2value = $(this).('.field2 input').val();  
                    alert(field2value);
          
    	},500);
    });
   
  });
  

Hi, try to assign the var first with a default value then overwrite it with the field value. Make sure the data in the lookup is the same type as the field example: lookup value=Date & field2value=Date

0 0
replied on April 20, 2018

Hi,

If your code depends on executing certain function after completing a lookup, rather than using a setTimeout function, I strongly suggest using the "lookupcomplete" method. This is a custom event that Forms offer since version 10.2. FYI we also offer custom methods such as "onloadlookupfinished" which is useful if your form contains lookup rules that automatically populate fields upon loading. 

$(document).on("lookupcomplete",function(){

//execute code here

})

0 0
replied on April 20, 2018

Hi Johan,
I tried your code but it still returned "undefined".

 

Hi Kentaro,

I am on Form 10 so the lookupcomplete event is not available.

 

Thank you so much for your help.

0 0
replied on April 20, 2018

I would double-check this part:

$(this).('.field2 input').val();

I don't have access to your form but there seems to be an error with your selector. If Field2 is your id, maybe try;

var field2value = $('input#Field2').val();

I would first try and make sure that the selector is working in console log. 

Also, if your lookup takes longer than 500ms, the code would not work. For testing, you can exaggerate the time a little bit and put 5000 for setTimeout. 

0 0
replied on April 20, 2018

The selector is correct. I field2 as class for the field i wanted to target. I also increased timeout to 5000 but it still returned "undefined". I believe that the auto-filled field2 does not see the lookup value at all. 

0 0
replied on May 24, 2018

Have you found a solution to this problem?

0 0
replied on May 24, 2018

Have you confirmed that you can grab the value?

For testing purpose, I would manually trigger the autofill and see if I can grab the value from console.log

I guess I'm not sure what .('.field2 input') is doing since it's not a method. Can it be $(this).find('.field2 input').val()? 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.