显示方法客户名称

时间:2016-09-20 12:52:57

标签: axapta dynamics-ax-2012

我创建了一个包含不同字段的新表格,其中一个是CustAccount,我希望在CustAccount旁边创建一个显示CustName的列。

我希望根据CustAccount的选择display客户名称。

我尝试使用表name上的现有方法CustTable,该方法包含以下代码:

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;
}

显示客户名称,但不基于CustAccount选项。我正在考虑将代码复制到我的新表上的新方法。如何编辑代码来完成此任务?

或者有更好的方法吗?

2 个答案:

答案 0 :(得分:4)

您不想将该方法复制到您的表格中。而是通过将此方法放在您的桌子上来引用它:

// BP deviation documented
display CustName name()
{
    return CustTable::find(this.CustAcccount).name();
}

答案 1 :(得分:0)

是的,这种方法Name()运行正常。也是其他方式。

我有两种方法可以得到你想要的东西:

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