Lookup field-Query

navfreshernavfresher Member Posts: 44
I have a field(,"Utilised Against Doc No") which has lookup.

requirement: That lookup leads to the posted invoices.Once i select any posted invoice,the correspoding vendor shipment no field should get updated on the on the same form.I have written the code on On Validate of the field "Utilised Against Doc No",but the code is not working.

Situation : But when i tried to copy the document number and paste it instead of using lookup,the code is working and the value is getting reflected in the other field.
purchInvheader.SETRANGE(purchInvheader."No.","Utilised Against Doc No");
IF purchInvheader.FINDFIRST THEN
BEGIN
   PurchReciptHeader.SETRANGE(PurchReciptHeader."Order No.",purchInvheader."Order No.");
   IF PurchReciptHeader.FINDFIRST THEN
    "Vendor Shipment No.":=PurchReciptHeader."Vendor Shipment No.";
END;


What could be the reason?Is it correct to write the code on On validate of that field?

Answers

  • matttraxmatttrax Member Posts: 2,309
    Your code is in the correct place and look to be written correctly at first glance. Try this:
    purchInvheader.SETRANGE(purchInvheader."No.","Utilised Against Doc No");
    IF purchInvheader.FINDFIRST THEN
    BEGIN
       IF NOT CONFIRM('Found the Invoice Header.\Look for receipt with order no %1 ?', FALSE, purchInvHeader."Order No.") THEN EXIT;
       PurchReciptHeader.SETRANGE(PurchReciptHeader."Order No.",purchInvheader."Order No.");
       IF PurchReciptHeader.FINDFIRST THEN BEGIN
        IF NOT CONFIRM('Found the Receipt Header. Continue?') THEN EXIT;
        "Vendor Shipment No.":=PurchReciptHeader."Vendor Shipment No.";
       END;
    END;
    

    You can also step through the debugger.
  • navfreshernavfresher Member Posts: 44
    Hi matttrax,

    I have used the debugger and came to know that the code is not running at all.Why it is not running?Why the field is not getting validated even after selecting the document number?

    Any reasons?What could be the problem?
  • lvanvugtlvanvugt Member Posts: 774
    Do you have any code in the OnLookup trigger of the Utilised Against Doc No field?
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • matttraxmatttrax Member Posts: 2,309
    Ah, I misunderstood.

    Are you using the default lookup functionality (just setting the TableRelation property on the field) or have you created custom lookup code in the OnLookup trigger for that field?
  • navfreshernavfresher Member Posts: 44
    matttrax wrote:
    Ah, I misunderstood.

    Are you using the default lookup functionality (just setting the TableRelation property on the field) or have you created custom lookup code in the OnLookup trigger for that field?

    I am using the default lookup functionality(By setting the TableRelation property)...
  • navfreshernavfresher Member Posts: 44
    I have found the solution for my problem...

    The field has some table realation defined as well and the same was written as code on the lookup of the field...That was the reason....

    Now i have removed the table relation and have written the code on the lookup of that field and its working fine...
  • lvanvugtlvanvugt Member Posts: 774
    So indeed there was code on the OnLookup trigger. :D
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • navfreshernavfresher Member Posts: 44
    lvanvugt wrote:
    So indeed there was code on the OnLookup trigger. :D

    yes,i have checked it after looking at your reply....Thank you...
  • navfreshernavfresher Member Posts: 44
    I have written the below code on Onlookup of a field after the lookup code of that field.This code is working fine.But the lookup code which was written over there is working only for the first line.When i am trying to enter the values in the second line of the form,the Lookup code is not working.
    is there anythng on this code which can stop the lookup code not work for the second time?
    purchInvheader.RESET;
    purchInvheader.SETRANGE(purchInvheader."No.","Utilised Against Doc No");
    IF purchInvheader.FINDFIRST THEN 
    BEGIN
       PurchReciptHeader.RESET;
       PurchReciptHeader.SETRANGE(PurchReciptHeader."Order No.",purchInvheader."Order No.");
       IF PurchReciptHeader.FINDFIRST THEN
        "Vendor Shipment No.":=PurchReciptHeader."Vendor Shipment No.";
    END;
    

    Any suggestions?
  • kapamaroukapamarou Member Posts: 1,152
    One reason is that the value of "Utilised Against Doc No" causes
    purchInvheader.SETRANGE(purchInvheader."No.","Utilised Against Doc No");
    
    to filter-out all records.

    What is the value of "Utilised Against Doc No" of the second line?

    If that is not the issue then maybe purchInvheader."Order No." applied as a filter to PurchReciptHeader leads to no records.
  • navfreshernavfresher Member Posts: 44
    kapamarou wrote:
    One reason is that the value of "Utilised Against Doc No" causes purchInvheader.SETRANGE(purchInvheader."No.","Utilised Against Doc No"); to filter-out all records.

    What is the value of "Utilised Against Doc No" of the second line?

    If that is not the issue then maybe purchInvheader."Order No." applied as a filter to PurchReciptHeader leads to no records.

    The value of "Utilised Against Doc No" is just a lookup field to select the Posted purchase invoice document no

    If PurchReciptHeader leads to no records then the field which has to get updated should be empty,but the lookup field itself is not working,i,e it is just showing empty form.

    The code which i have posted in the previous post is to update another field on the same form .It is not written for the lookup.
  • lvanvugtlvanvugt Member Posts: 774
    Why are you creating a new thread when we have been discussing this issue alreade here: http://www.mibuso.com/forum/viewtopic.php?f=23&t=39293&p=192116#p192116?

    The code should not be in the OnLookup trigger!
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • navfreshernavfresher Member Posts: 44
    lvanvugt wrote:
    Why are you creating a new thread when we have been discussing this issue alreade here: http://www.mibuso.com/forum/viewtopic.php?f=23&t=39293&p=192116#p192116?

    The code should not be in the OnLookup trigger!

    Then where am i supposed to write the code?
  • lvanvugtlvanvugt Member Posts: 774
    The code you have written can been seen as business logic that is based on the validation of a valuie entered in the Utilised Against Doc No field. So this is code to be put in the OnValidate trigger of that field. I seem to recall from the other thread that there is where you had put it already.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • krikikriki Member, Moderator Posts: 9,110
    [Merged another topic into this topic]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.