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:
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.
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.
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.
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
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.
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.
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.
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.
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.
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 answers
Comments
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.
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.
RIS Plus, LLC
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 advance
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 better
http://www.BiloBeauty.com
http://www.autismspeaks.org
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.
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.
http://www.BiloBeauty.com
http://www.autismspeaks.org
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.
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 forum
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: 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 helps
RIS Plus, LLC
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.
RIS Plus, LLC