Get Record fields value

snow_capsnow_cap Member Posts: 17
hey am a new at dynamics nav and i am having a problem in getting all the values of a record from C/AL code
Example:The Vendor Card Form
I have added a new button to that form and i am sending some values to a webservice.
On clicking on the button i need to send the related record with all it's values to the webservice
like :select * from vendore where No.="the id related to the opened vendor" but i need to do that in C/AL

Comments

  • philippegirodphilippegirod Member Posts: 191
    A Variable record contains all field values for this record, you can make an easy test to see that, for instance in your form :
    MESSAGE(FORMAT(Rec));
    
    FORMAT is used to convert the record into a text.

    As you can see, the fields value are separated by a Tab, which could be difficult to use to send the data to another table or system.
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • DenSterDenSter Member Posts: 8,304
    When you are on a form, Rec refers to the record that is currently displayed on the form, and doesn't even have to be specified. So a reference to the Name of the Vendor on the Vendor card can be made by "Rec.Name", or even "Name".

    Create a new test form, based on the Vendor table, just put some random fields on there. Put a button on there, and in the code of the button put this C/AL code:
    MESSAGE(Name);
    MESSAGE(Rec.Name);
    
    You should get two messages, both with the name of the current vendor. Move your cursor to a different vendor and click the button again, and verify that it puts the current Vendor name in there.
  • snow_capsnow_cap Member Posts: 17
    hey thank guys well the MESSAGE(FORMAT(Rec));
    is returning zeros ,i created a new test form and it has returned good data but while using the vendor card form it returns only zeros

    For the second solution what if i want to make it dynamic and i don't know what are the fields name
    Thank you again
  • snow_capsnow_cap Member Posts: 17
    sorry i forgot to ask about the following can i get the fields name also
    eg table vendor
    i need to get the fieldname and their values per record i don't care if it is going to be a datatable i will send them as string
    Enabled Field No. Field Name Data Type Length Description
    Yes 1 No. Code 20
    Yes 2 Name Text 50
    Yes 3 Search Name Code 50
    Yes 4 Name 2 Text 50
    Yes 5 Address Text 50
    Yes 6 Address 2 Text 50
    Yes 7 City Text 30
    Yes 8 Contact Text 50
    Yes 9 Phone No. Text 30
    Yes 10 Telex No. Text 20
    Yes 14 Our Account No. Text 20
    Yes 15 Territory Code Code 10
    Yes 16 Global Dimension 1 Code Code 20
    Yes 17 Global Dimension 2 Code Code 20
    Yes 19 Budgeted Amount Decimal
    Yes 21 Vendor Posting Group Code 10
    Yes 22 Currency Code Code 10
    Yes 24 Language Code Code 10
    Yes 26 Statistics Group Integer
    Yes 27 Payment Terms Code Code 10
    Yes 28 Fin. Charge Terms Code Code 10
    Yes 29 Purchaser Code Code 10
    Yes 30 Shipment Method Code Code 10
    Yes 31 Shipping Agent Code Code 10
    Yes 33 Invoice Disc. Code Code 20
    Yes 35 Country/Region Code Code 10
    Yes 38 Comment Boolean
    Yes 39 Blocked Option
    Yes 45 Pay-to Vendor No. Code 20
    Yes 46 Priority Integer
    Yes 47 Payment Method Code Code 10
    Yes 54 Last Date Modified Date
    Yes 55 Date Filter Date
    Yes 56 Global Dimension 1 Filter Code 20
    Yes 57 Global Dimension 2 Filter Code 20
    Yes 58 Balance Decimal
    Yes 59 Balance (LCY) Decimal
    Yes 60 Net Change Decimal
    Yes 61 Net Change (LCY) Decimal
    Yes 62 Purchases (LCY) Decimal
    Yes 64 Inv. Discounts (LCY) Decimal
    Yes 65 Pmt. Discounts (LCY) Decimal
    Yes 66 Balance Due Decimal
    Yes 67 Balance Due (LCY) Decimal
    Yes 69 Payments Decimal
    Yes 70 Invoice Amounts Decimal
    Yes 71 Cr. Memo Amounts Decimal
    Yes 72 Finance Charge Memo Amounts Decimal
    Yes 74 Payments (LCY) Decimal
    Yes 75 Inv. Amounts (LCY) Decimal
    Yes 76 Cr. Memo Amounts (LCY) Decimal
    Yes 77 Fin. Charge Memo Amounts (LCY) Decimal
    Yes 78 Outstanding Orders Decimal
    Yes 79 Amt. Rcd. Not Invoiced Decimal
    Yes 80 Application Method Option
    Yes 82 Prices Including VAT Boolean
    Yes 84 Fax No. Text 30
    Yes 85 Telex Answer Back Text 20
    Yes 86 VAT Registration No. Text 20
    Yes 88 Gen. Bus. Posting Group Code 10
    Yes 89 Picture BLOB
    Yes 91 Post Code Code 20
    Yes 92 County Text 30
    Yes 97 Debit Amount Decimal
    Yes 98 Credit Amount Decimal
    Yes 99 Debit Amount (LCY) Decimal
    Yes 100 Credit Amount (LCY) Decimal
    Yes 102 E-Mail Text 80
    Yes 103 Home Page Text 80
    Yes 104 Reminder Amounts Decimal
    Yes 105 Reminder Amounts (LCY) Decimal
    Yes 107 No. Series Code 10
    Yes 108 Tax Area Code Code 20
    Yes 109 Tax Liable Boolean
    Yes 110 VAT Bus. Posting Group Code 10
    Yes 111 Currency Filter Code 10
    Yes 113 Outstanding Orders (LCY) Decimal
    Yes 114 Amt. Rcd. Not Invoiced (LCY) Decimal
    Yes 116 Block Payment Tolerance Boolean
    Yes 117 Pmt. Disc. Tolerance (LCY) Decimal
    Yes 118 Pmt. Tolerance (LCY) Decimal
    Yes 119 IC Partner Code Code 20
    Yes 120 Refunds Decimal
    Yes 121 Refunds (LCY) Decimal
    Yes 122 Other Amounts Decimal
    Yes 123 Other Amounts (LCY) Decimal
    Yes 124 Prepayment % Decimal
    Yes 125 Outstanding Invoices Decimal
    Yes 126 Outstanding Invoices (LCY) Decimal
    Yes 130 Pay-to No. Of Archived Doc. Integer
    Yes 131 Buy-from No. Of Archived Doc. Integer
    Yes 5049 Primary Contact No. Code 20
    Yes 5700 Responsibility Center Code 10
    Yes 5701 Location Code Code 10
    Yes 5790 Lead Time Calculation DateFormula
    Yes 7177 No. of Pstd. Receipts Integer
    Yes 7178 No. of Pstd. Invoices Integer
    Yes 7179 No. of Pstd. Return Shipments Integer
    Yes 7180 No. of Pstd. Credit Memos Integer
    Yes 7181 Pay-to No. of Orders Integer
    Yes 7182 Pay-to No. of Invoices Integer
    Yes 7183 Pay-to No. of Return Orders Integer
    Yes 7184 Pay-to No. of Credit Memos Integer
    Yes 7185 Pay-to No. of Pstd. Receipts Integer
    Yes 7186 Pay-to No. of Pstd. Invoices Integer
    Yes 7187 Pay-to No. of Pstd. Return S. Integer
    Yes 7188 Pay-to No. of Pstd. Cr. Memos Integer
    Yes 7189 No. of Quotes Integer
    Yes 7190 No. of Blanket Orders Integer
    Yes 7191 No. of Orders Integer
    Yes 7192 No. of Invoices Integer
    Yes 7193 No. of Return Orders Integer
    Yes 7194 No. of Credit Memos Integer
    Yes 7195 No. of Order Addresses Integer
    Yes 7196 Pay-to No. of Quotes Integer
    Yes 7197 Pay-to No. of Blanket Orders Integer
    Yes 7600 Base Calendar Code Code 10
  • DenSterDenSter Member Posts: 8,304
    snow_cap wrote:
    For the second solution what if i want to make it dynamic and i don't know what are the fields name
    That is just not very practical in C/AL code. You could use recref variables for that, but that is very cumbersome to program. It seems you are a VB or C# programmer that is working with NAV now. I'd suggest you study the development training material to familiarize yourself with how C/AL works. Not just the syntax but the way you work with data. It's quite different from how you'd do that in VB.
  • snow_capsnow_cap Member Posts: 17
    well yes am a c# developper and am trying to migrate the data of navision to sharepoint i need to create the table vendor in sharepoint and fill the necessary data any way from where can i start i bought some ebooks but nothing much in it but still we can export the data to excel right??so this should be feasible after all in any language i guess it might take time yes but with your help i can make something
  • DenSterDenSter Member Posts: 8,304
    You know I'd love to help, but if your question changes from sending the value of a record on a form to a webservice to filling a table on Sharepoint (I didn't even know Sharepoint has a database) to creating an excel file, I really don't know where to start.

    Are you working on the purchase order approval process in Sharepoint that was in another post?
  • snow_capsnow_cap Member Posts: 17
    no actually am working something else yes u can create a table in sharepoint the fields are going be content types that's why i need the fields name and their values using the fields name i can create the content type and the values i can fill them by their values
  • snow_capsnow_cap Member Posts: 17
    I managed to add a new global variable name recfield type record subtype field but still i didn't get how to make it work
  • snow_capsnow_cap Member Posts: 17
    I am kind of desperate here i downloaded the tableinformer from mibuso and once u select a table it will get all the fields of the table in a list and export its data to a txt file that means we can get the fields name what i am missing is the good syntax of CAL like recfield.GET and that sort of stuff can anyone help me from where i can get anything concerning the syntax and please please if anyone can help me in getting the the names of the fields like in the tableinformer but in a text variable i would be really thankful.

    Thank you
  • DenSterDenSter Member Posts: 8,304
    snow_cap wrote:
    what i am missing is the good syntax of CAL like recfield.GET and that sort of stuff
    How are you expecting us to interpret this? It's not even a question, and you're not describing what it is that you want :-k
  • snow_capsnow_cap Member Posts: 17
    ok the MESSAGE(FORMAT(Rec)) will give me all the values of the selected record right??
    i just need to do the same but i need to get the names of the fields of the table
    that's all i want i added a new global variable recfield of type record and subtype field
    in CAL code i have seen many code syntax like
    recfield.GET;
    My question is how can i know what can i do with "recfield" like the properties of recField how can i use recfield??
    i am really ssorry for disturbing but i am new and i hope u can understand how new people might interact with nav especially if they are a .net developper.
    thank you again and if you can check the tableinformer example u will get to understand what i need in the tableinformer example we are able to list the fields name in a listview all i want is to put them in a string variable but because i am not much with the CAL good syntax am stuck.
  • DenSterDenSter Member Posts: 8,304
    snow_cap wrote:
    My question is how can i know what can i do with "recfield" like the properties of recField how can i use recfield??
    Hit F5 to open the object browser. In there you should find your rec variable, and you can browse through properties and methods and such. About the Field table, I never use the field table. Unless you have a specific question I can't help you out.
    snow_cap wrote:
    i am really ssorry for disturbing but i am new and i hope u can understand how new people might interact with nav especially if they are a .net developper.
    I hope you can see that I am trying to understand what you mean. Your questions are just not clear to me, so all I am asking what you mean
    snow_cap wrote:
    you can check the tableinformer example u will get to understand what i need in the tableinformer example
    How am I supposed to know what YOU want by looking at some example???
    snow_cap wrote:
    we are able to list the fields name in a listview all i want is to put them in a string variable but because i am not much with the CAL good syntax am stuck.
    You create variables in the globals window (View, Globals). Add a new line, set the variable name, set the type as text, with the proper length. Then assign the variable to whatever text you want, it works the same as in .NET. Assignment statements use this code:
    MyTextVariable := MyRecordVariable."Text Type Field";
    
    If the field is a type that doesn't automatically convert to a text, you use FORMAT, like this:
    MyTextVariable := FORMAT(MyRecordVariable."Some Other Type Field");
    
    Is that what you want?
  • snow_capsnow_cap Member Posts: 17
    hey actually what i wanted was like the below



    RecRef.OPEN(23)
    RecRef.FINDFIRST;
    FOR i := 1 TO RecRef.FIELDCOUNT DO BEGIN
    fldItemFields := RecRef.FIELDINDEX(i);
    str := STRSUBSTNO('%1 = %2',fldItemFields.NAME,fldItemFields.VALUE);
    MESSAGE(str);
    END;
  • garakgarak Member Posts: 3,263
    take a look on RecRef and FieldRef.


    EDIT: Arg .... your'e find it self and i forgott to press submit

    regards
    Do you make it right, it works too!
  • snow_capsnow_cap Member Posts: 17
    sorry garak i didn't understand ur last reply can you explain more like a small example :D and i don't know if u can help in this but as u have seen in my last post i have put recref.open(23); the table id is fix so from a form how i can get the table ID.
  • snow_capsnow_cap Member Posts: 17
    sorry forgot to post the following my solution will always give me the first record of the table but what i am working on i am like on form vendor and i am on the second record i will press a button and it is going to give same as done in the previous post but for the record am working on.
  • garakgarak Member Posts: 3,263
    RecRef.GETTABLE(Rec); //Rec is the current Record. GetTable gets the table id
    

    and then your loop after this.

    Regards
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    You get the first REc, because u use the findfirst command ;-)
    with gettable(Rec) you are on the same rec in RecRef that you see on your form.
    If you wan't also loop trough the rec, you can do this also with this example.
    RecRef.GETTABLE(Rec);
    if RecRef.FIND('-') then begin
      repeat
        FOR i := 1 TO 4 DO BEGIN
          if RecRef.FIELDEXIST(i) then begin
            FieldsRef := RecRef.FIELDINDEX(i);
            if FieldsRef.ACTIVE then begin
              str := STRSUBSTNO('%1 / %2 / %3 / %4',FieldsRef.NAME,FieldsRef.VALUE,FieldsRef.TYPE,FieldsRef.LENGTH);
              MESSAGE(str);
            end;
          end;
        END;
      until RecRef.next = 0;
    end;
    

    Regards
    Do you make it right, it works too!
  • snow_capsnow_cap Member Posts: 17
    I would really like to thank you but one more thing is missing the solution you gave me is giving me all the records in the table i just want to get the fields and their values of a selected record i mean the record opened in the form.

    Thank you and Best regards
  • garakgarak Member Posts: 3,263
    read the post above your last post.

    The loop is only an example how to get all recs in the table.
    So in your case, RecRef.gettable(Rec); is enough.
    The 4 in the "for" loop is also only an example (use RecRef.Fieldcount) beacuse im to lazy to press 100x Enter when the messages pops up ;-)

    Regards
    Do you make it right, it works too!
  • snow_capsnow_cap Member Posts: 17
    ok solved sorry but how i can set the solution as solved :D but one more last question i did
    str :=str+ STRSUBSTNO('Field %1 has value %2',fldItemFields.NAME,fldItemFields.VALUE);

    and str is a text and as u know text is with a lenght 1024 so it is always giving me a break error i tried a big text but didn't know how to use it well

    Last from where i can get examples on how to use all these variables and how to know the synthax of CAL i have used the F1 seen in an earlier post of you but still it is not that much clear for a begginner in NAV especially trying to integrate sharepoint and NAV and a .net developper.

    Thank you again
  • DenSterDenSter Member Posts: 8,304
    Check out the C/SIDE Reference Guide. It's under the Help menu, right underneath F1 Help. In there you'll find all properties and keywords, with tons of code samples.
  • snow_capsnow_cap Member Posts: 17
    I've checked the help but still like if i want to use bigtext ok i can add my string using

    bigtext.addtext(str);
    but still i can't read it or use it wihtout writing it as a stream and the examples in the help aren't that much wide you also need to have a small knowledge in NAV to understand what they are talking about.

    1-how i can create a string variable that can take more than 1024 as length. is nav that much limited??

    2-i am using a com and i call it in my CAL code as automation,i have a function in c# that returns a string ok that's great i can read that from NAV,i've created another function in c# that returns an arraylist,can i read that from nav if i have created a text array,because i tried to use:
    array:=format(navWs.getDocuments);
    but i can never compile because i can't use array:= it has to be array[1]:= any ideas???
    a small request if i am in codeunit and i want to insert values in a new table i have created how can i do that a small example might be helpfull.

    Thank you and best regards
  • PhennoPhenno Member Posts: 630
    snow_cap wrote:
    2-i am using a com and i call it in my CAL code as automation,i have a function in c# that returns a string ok that's great i can read that from NAV,i've created another function in c# that returns an arraylist,can i read that from nav if i have created a text array,because i tried to use:
    array:=format(navWs.getDocuments);
    but i can never compile because i can't use array:= it has to be array[1]:= any ideas???


    Hi,


    have you ever found a solution for accessing arraylist in COM?
    I have a situation where I need to give an arraylist to a function as a parameter in COM but can't manage to do that...
  • matttraxmatttrax Member Posts: 2,309
    There's always a way around it. If you have an array that you can't pass to COM then you can pass the individual objects in that array to an AddToArray type method. Not clean, but it should work.
  • PhennoPhenno Member Posts: 630
    Actually, my COM is asking for arraylist (.net) to pass it but I can't manage to do that. If I pass automation then runtime error occures.

    I found .net component that someone also gave as type library after which I can call it from NAV over COM.
    In that .net component, there is one collection (of objects). In COM (through Navision) I see that collection as properties in appropriate object, to which I can pass Arraylist (of collection objects).

    I know that somewhere should be Add (or Count) method but can't find it. If I pass automation (object) to that properties, it compiles but runtime error occures.

    The actual question is, how can I pass arraylist (of objects) to COM function?
  • Markandey_PandeyMarkandey_Pandey Member Posts: 178
    snow_cap wrote:
    hey actually what i wanted was like the below



    RecRef.OPEN(23)
    RecRef.FINDFIRST;
    FOR i := 1 TO RecRef.FIELDCOUNT DO BEGIN
    fldItemFields := RecRef.FIELDINDEX(i);
    str := STRSUBSTNO('%1 = %2',fldItemFields.NAME,fldItemFields.VALUE);
    MESSAGE(str);
    END;

    As i am new to navision, can u please give me the complete code
    Markandey Pandey
Sign In or Register to comment.