Options

declare arrays

kikkomankikkoman Member Posts: 57
i know this may be a simple question, but i need to add a dimension code to a posted purchase inv. line, and the dimension is called "Employee". I am a newbie, and I know that you can have multiple Lines for each Header. Anyhow, I went to the Posted Puch. Invoice Subform, and I added a column called Employee Code. Anyhow, I was able to show the Dimension code when the form loads b/c I filtered the Posted Docuement Dimension by "Table ID", "Document No", and "Dimension Code". The problem I have is that when I have like 3 lines on the Posted Purch. Inv form, it shows for all 3 lines the Employee Code for the 1st line. This is not correct b/c each line can have a different Employee Code. I was thinking that maybe I can use an array and then assign the textbox for EMployee code on my form to the array, but I don't know if I can do this or not. Also i have looked on this forum and couldn't find how to declare arrays :cry: Can someone please help me with this. How to declare arrays correctly. And if my method of assigining the SourceExpr for the textbox for Employee Code to the array will work, or is there another easy way of doing this??? I'm sure there has to be!!!! any help is greatly appreciated.

Comments

  • Options
    mjrogersmjrogers Member Posts: 59
    Hi,

    Have you tried assigning the value to your variable at the OnAfterGetRecord section of the subform? That should do it. Under most circumstances you shouldn't need to use an array. However, to set the dimensions of an array you need to look at the properties of your variable.


    I hope I understood your need and that this helps.
    TecSA Malaysia

    Those of you who think you know everything are annoying to those of us who do. -
    David Brent
  • Options
    kikkomankikkoman Member Posts: 57
    yes i assigned my value to my variable and i get the correct code, but if the line has more than 1 entry, all those entries get assigned to the very first one. for instance, the first line the employee code is martin, then if there are like 3 lines, then they all are martin, when it should be 1(martin), 2(brad), 3(sarah). if i just have a variable named EmpCode and assign that variable to the SourceExpr of the textbox, no matter what, all the lines are going to be the same b/c the variable is assigned to the SourceExpr, that is why I was thinking about using an array. Does this make sense? Im sorry if it doesn't.
  • Options
    mjrogersmjrogers Member Posts: 59
    Well, I did a simple test:

    In the OnAfterGetRecord of the Subform:

    myvar := format("line no.");

    myvar = code 10

    I added a new column to the subform and made SourceExpr myvar

    It shows each line number correctly.

    So... I'm guessing your problem might be in the code you use to retrieve the dimension value for each line.
    TecSA Malaysia

    Those of you who think you know everything are annoying to those of us who do. -
    David Brent
  • Options
    kikkomankikkoman Member Posts: 57
    EmpCode:='';
    PostedDocDimension.RESET;
    PostedDocDimension.SETRANGE("Table ID", DATABASE::"Purch. Inv. Line"); {filter by table "Purch.Inv.Line" b/c that is where the
    Posted Invoice Doc go. }

    PostedDocDimension.SETRANGE("Document No.","Document No."); {filters the "Document No." field in table PostedDocDimension with
    the field named "Document No." that is in this table,"Purch. Inv. Line" }

    PostedDocDimension.SETRANGE("Dimension Code", 'EMPLOYEE');
    //Employee is the 3rd dimension I need to filter

    IF PostedDocDimension.FIND('-') THEN
    REPEAT
    EmpCode:=PostedDocDimension."Dimension Value Code";
    //this will only get the last match of Employee Code and set all
    //lines in Posted Purchase Invoice(line) to it, which is wrong b/c
    //they can be different.
    UNTIL PostedDocDimension.NEXT <=0;



    Here is how my code looks like in the OnAfterGetRecord()
    this is of course incorrect b/c all the empcodes on the form will be the same. Are you suggesting that I use the FORMAT to format my source expression??? It makes sense when you do it, but when I try, it doesn't work. It may be where I place that line of code???
  • Options
    mjrogersmjrogers Member Posts: 59
    With your solution you are missing the SETRANGE on the "line no." and you don't need the repeat:
    PostedDocDimension.RESET;
    PostedDocDimension.SETRANGE("Table ID", DATABASE::"Purch. Inv. Line");  
    PostedDocDimension.SETRANGE("Document No.","Document No.");    
    PostedDocDimension.SETRANGE("Line no.","line no.");
    PostedDocDimension.SETRANGE("Dimension Code", 'EMPLOYEE');
    
    IF PostedDocDimension.FIND('-') THEN
      EmpCode:=PostedDocDimension."Dimension Value Code";       
    

    You could of course just do this:
    clear(EmpCode);
    
    If postedDocDimension.get(DATABASE::"Purch. Inv. Line","Document No.","line no.",'EMPLOYEE') then
        EmpCode:=PostedDocDimension."Dimension Value Code";       
    


    The format in my example has nothing to do with your problem.. just a red herring I threw in ;)
    TecSA Malaysia

    Those of you who think you know everything are annoying to those of us who do. -
    David Brent
  • Options
    kikkomankikkoman Member Posts: 57
    sweet....it works!!! hmm, i didn't know you had to place the RANGE on the "Line No." as well....doh!!! Thanks a bunch!!! I also like your short-handed version of my code. Alot more efficient. This is my 2nd week working with Navision. I have programmed before, but never with Navision, so I'm getting myself up to par with the material, or at least trying to. I'm sure glad for this website and for people like you. Very helpful. I hope to gain as much knowledge as I can so I can help others also....return the favor!!!hehehe :lol:

    thanks,
Sign In or Register to comment.