Reputation: 281
I have created a new table with different fields, 1 of them is CustAccount
, in the form i want to create a column next of CustAccount
showing the CustName
.
I want to display
the Customer Name, based on the selection of the CustAccount.
I have tried using the existing method name
on the table CustTable
, which contains the following code:
display CustName name()
{
DirPartyTable dirPartyTable;
CustName custName;
boolean isSet = false;
try
{
if (this.hasRelatedTable(identifierStr(DirPartyTable_FK)))
{
dirPartyTable = this.relatedTable(identifierStr(DirPartyTable_FK)) as DirPartyTable;
//Check to make sure the fields we are accessing are selected.
if (dirPartyTable && dirPartyTable.isFieldDataRetrieved(fieldStr(DirPartyTable, Name)))
{
custName = dirPartyTable.Name;
isSet = true;
}
}
}
catch (Exception::Error)
{
isSet = false;
}
//If we aren't joined to DirPartyTable or it isn't selected, then do a query to get it.
if(!isSet)
{
custName = DirPartyTable::getName(this.Party);
}
return custName;
}
This displays a customer name, except not based on the CustAccount selection. I am thinking about copying the code to a new method on my new table. How do I edit the code to accomplish this?
Or is there a better way?
Upvotes: 0
Views: 2233
Reputation: 2238
Yes this method Name()
work fine. Also are others ways.
I leave two ways to get what you want:
CustTable CustTable;
AccountNum pCust;
str cName;
DirPartyTable DirPartyTable;
;
//First option
pCust = "YourCustomer";
Select * from CustTable where CustTable.AccountNum == pCust;
cName = CustTable.name(); //Get Name
//First option END
//Second option
pCust = "YourCustomer";
Select Party from CustTable where CustTable.AccountNum == pCust
join DirPartyTable where DirPartyTable.RecId == CustTable.Party;
cName = DirPartyTable.Name; //Get Name
//Second option END
Upvotes: 0
Reputation: 11544
You don't want to copy that method to your table. Instead refer to it by putting this method on your table:
// BP deviation documented
display CustName name()
{
return CustTable::find(this.CustAcccount).name();
}
Upvotes: 4