Can't assign value from a field to a variable

remark
Member Posts: 122
Please, help a beginner!
For using in a report I need to retrieve a value from a field in a record and assign it to a variable.
When I try in such way:
varCODE := someRecord.fieldCODE
nothing happens.
I am sorry :oops: , but give me please a hint.
For using in a report I need to retrieve a value from a field in a record and assign it to a variable.
When I try in such way:
varCODE := someRecord.fieldCODE
nothing happens.
I am sorry :oops: , but give me please a hint.
0
Comments
-
If someRecord is a dataitem on your report varCODE should be filled with a value when there is a value in the record. Maybe you have defined some filters so that no record is found?
If someRecord is not a dataitem but a global or a local. Then you first have to a someRecord.FIND or someRecord.GET to retriev the value from the someRecord table.0 -
Simply assigning a variable does indeed do something, but you don't see it. It assigns a spoace in the computer's memory, and puts a value in it. Unless you use the variable somewhere (such as using it as the source expression of a report control) you will not see it.
If you do have it as the source expression in a control, then you might want to check in which trigger you set the variable. You need to make sure that it puts a value in at a time that it actually HAS a value, for instance in the OnAfterGetRecord trigger of the proper dataitem.
For sure though, we will need more information about what you are doing, what you want to do, and how you plan to achieve that goal.0 -
Maximus wrote:If someRecord is a dataitem on your report varCODE should be filled with a value when there is a value in the record. Maybe you have defined some filters so that no record is found?
If someRecord is not a dataitem but a global or a local. Then you first have to a someRecord.FIND or someRecord.GET to retriev the value from the someRecord table.
This record is not a dataitem in this report. It's a global.
Could you please give me any example code with AnyRecord.FIND and AnyRecord.GET in order I could analize it for myself to realize its usage.
Thank you in advance0 -
if you have sales line dataitem and you need a field from the header
Salesheader.GET(SalesLine."Document Type",SalesLine."Document No.");
//Using the dataitem (salesline) info to fill in the KEY of the GET table(salesHeader).
[So SalesHeader's Key of "Document Type" & "No." get filled in]
Define Variable SalesHeader - type:Record - Sales Header
Now you can use SalesHeader.AnyField
I guess some people can explain it better0 -
DenSter wrote:Simply assigning a variable does indeed do something, but you don't see it. It assigns a spoace in the computer's memory, and puts a value in it. Unless you use the variable somewhere (such as using it as the source expression of a report control) you will not see it.
If you do have it as the source expression in a control, then you might want to check in which trigger you set the variable. You need to make sure that it puts a value in at a time that it actually HAS a value, for instance in the OnAfterGetRecord trigger of the proper dataitem.
For sure though, we will need more information about what you are doing, what you want to do, and how you plan to achieve that goal.
Thank you, DenSter, I will try to explain.
My report is connected with Sales Order and "Sales Header" is a DataItem for this report.
In report I should show a client's bank account information. I can't get it from "Sales Header" itself, there isn't any. I must retrieve it from another table "Customer Bank Account".
So, I try this way:
CustBankAcc.GET(CustNo)
And parameter "CustNo" should be assigned a "No." of Customer in current Sales Order.
With this very assignment I am not successful.0 -
Is Cust No the only fields in the primaryKey of this Cust Bank Accout Table?
If so Use "Bill-To Customer No." Instead of Cust No.
Also if this "Bank Account No" field is available on the customer table.
Customer.GET("Bill-To Customer No.");
example/
Customer."Bank Account No" can now be used.0 -
Savatage wrote:Is Cust No the only fields in the primaryKey of this Cust Bank Accout Table?
If so Use "Bill-To Customer No." Instead of Cust No.
Also if this "Bank Account No" field is available on the customer table.
Customer.GET("Bill-To Customer No.");
example/
Customer."Bank Account No" can now be used.
The "Customer No." isn't the only primaryKey in the Cust Bank Account Table. There is Code (the name of bank account) as well. I'm planning to make possible for user to choose this Code (the name of bank account) from the Sales Order form. So, if I realize how to handle "Customer No." as a parameter for getting out CustomerBankAccount information, for second parameter, I guess, it will be much the same.
Sorry, if my explanation is a bit confused.0 -
YOu should really take a look at the application designer's guide to learn these basic programming concepts.
get uses the primary key so
CustomerBankAccount.get( BankCode, SalesHeader."Bill-to Customer No." ) ;
find will get you a record set based on your filters if you don't have the PK
CustomerBankAccount.setrange( "customer no.", CustNo ) ;
CustomerBankAccount.find('-') ;
Just post your code as text to the forum0 -
Primary key of the Customer Bank Account table is: Customer No.,Code, so if you want to use GET, you have to pass the primary key fields in the correct order, so Customer number first, bank account code second.
Being on the Sales Header dataitem, you only have access to a customer number, let's say you want to use the "Sell-to Customer No." field. There's no bank account number on the sales header, so you only have one of the primary key fields. Since you can only use GET if you have ALL primary key fields, you will have to set a filter and use FINDFIRST. Add a record variable based on the Customer Bank Account table, and program in the OnAfterGetRecord trigget of the Sales Header dataitem:CustBankAccount.SETRANGE("Customer No.","Sales Header"."Sell-to Customer No."); IF CustBankAccount.FINDFIRST THEN BEGIN // now you should have the first one in the list of bank accounts related to the sell-to customer on the sales header END ELSE BEGIN // no bank account related to the customer was found END;
If you know where to find the right bank account code, then you will have to program something to retrieve that first, and in that case you can use GET.
NOTE: see how I used "Sales Header"."Sell-to Customer No.". You don't have to set a variable to a field value before being able to use it first, you can get to table fields directly. What you need to do though is make sure you are in the right trigger.
You should really get some training. You can get the official training material, or get Dave Studebaker's book. While that is sent to you, read the application designers guide.
Hope that helps0 -
Thank you everybody!
I've done it. And realize a lot.
DenSter, your last example and comments were exactly what I needed at that moment. Thank you very much. It was really helpful.
Concerning my learning. Today I have ordered the Dave Studebaker's book. And I've been reading Application Designer's Guide for last several months. Though it doesn't look so from my posts, sorry. :oops:
Thanks to all, once again.0 -
You're welcome, always happy to help. We were all where you are now, so don't worry about not knowing something. Before you know it you will be posting answers0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions