Field is no code field

Red-EagleRed-Eagle Member Posts: 107
I have now a working dataport (with some hulp from this forum, thanks again), but i have a small problem.

In the purchase line table their is a field called "Manufacturer". I want to link this field at ETIM Vendor (Central Mgt) table. The problem is that the keyfield of this table is "Code", but i need to link it at the field "Alternative Vendor Code" which is the same as Manufacturer.

The Manufacturer says for example 'ABB'

This is a example of this table.

Code Alternative Code
8712507900029 ABB
ABB ""

The problem is that when you choose Code you will find 'ABB' but then the field "Alternative Vendor Code" is empty.

Answers

  • TonyHTonyH Member Posts: 223
    I "think" I understand what you are looking for, to be able to select a value from a table that is not its key.

    You would need to add code on the OnLookup and OnValidate to make this work and remove the TableRelation. Add this on the table level and not the form level so it applies everywhere the field is shown.
    OnLookup
    ETIMVend.Reset;
    <Apply needed filters to ETIMVend>
    If Form.Runmodal(0,ETIMVend) = Action::Lookupok then
      Manufacuter := ETIMVend."Alternative code";
    

    You would also need to add it to the OnValidate to ensure that if a user does not lookup but type in a value it does not accept it without checking.
    OnValidate
    If (Manufacturer <> '') and (Manufacturer <> Xrec.Manufacturer) then begin
      ETIMVend.Reset;
      <Depending on your database and table records you might want to apply a new key and setcurrentkey)
      <Apply needed filters to ETIMVend>
      ETIMVend.Setrange("Alternative code", Manufacturer); 
      If ETIMVend.IsEmpty then
        FieldError(Manufacter)
    End;
    

    I just knocked this up without writing it IN Nav, so you may need to tweak it as needed, I also could have missed what you were looking for completelty.

    t
  • Red-EagleRed-Eagle Member Posts: 107
    I need it only for this dataport, but i was thinking. Isnt it possible to get the code ABB (which it is in the table) and then look for a field in that table where the alternative Vendor Code is the same and then get the code which is mentioned with that alternative vendor Code?
  • TonyHTonyH Member Posts: 223
    Sorry, was speed reading, missed the "Dataport" part...

    But now I am a little confused as to what you are looking for...

    t
  • Red-EagleRed-Eagle Member Posts: 107
    Okay i will try to give you more information.

    This is how the table (ETIM Vendor (Central Mgt)) is loooking.

    Code...................Name...............................................Vendor.............................................Alternative Vendor Code
    8712507900029.....ABB Systeemcomponenten................................................................................ABB
    8714252011920.....Phoenix Contact..............................................................................................PHO
    ABB.....................ABB Systeemcomponenten....................L1005......................................................''
    PHO.....................Phoenix Contact................................ L1044......................................................''

    I have from the purchase line table the field Manufacturer, which is for example 'ABB'. Now is it possible to link this field to the code field in table ITEM VENDOR, that isnt the problem. As you can see the same code is find in the field Alternative Vendor Code. What i want is to link to that field, so that i cen get de code which al those numbers in this case 8712507900029.
  • helmhelm Member Posts: 46
    If I understand you properly something like this should work:

    ETIMVend.SETRANGE("Alternative Vendor Code",PurchLine.Manufacturer);
    IF ETIMVend.FINDSET THEN //This might find several lines with PurchLine.Manufacturer, you have to decide how to handle this
    REPEAT
    ETIMvendorCode := ETIMVend.Code;
    UNTIL ETIMVend.NEXT = 0;

    If several lines are found the variable ETIMVendorCode will get the last one with the above code. Might not be what you want.
  • Red-EagleRed-Eagle Member Posts: 107
    Thank you for the help

    The problem is solved. Only i did it just a little bit different:


    Etimvendorrec.SETCURRENTKEY("Alternative Vendor Code");
    Etimvendorrec.SETRANGE("Alternative Vendor Code","Purchase Line".Manufacturer);
    IF Etimvendorrec.FIND ('-') THEN
    IF Manufacturer <> '' THEN BEGIN
    vEtimEAN := Etimvendorrec.Code;
    END ELSE BEGIN
    vEtimEAN := '';
    END;


    It working so i am very happy now!
Sign In or Register to comment.