Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Unanswered

Cannot retrieve customer primary address values in form

(1) ShareShare
ReportReport
Posted on by 207
I am new to X++ and trying to build a new form which shows related data of customer, including the primary address info of the customer.
In the new form, I added 3 data sources and defined their properties as follows:
1. CustTable; Join Source: blank; Link Type: blank
2. DirPartyTable; Join Source: CustTable; Link Type: Inner Join
3. LogisticsPostalAddress; Join Source: DirPartyTable; Link Type: Outer Join
 
I override these data sources's init() to define the relationship between them 
 
[DataSource]
class DirPartyTable
{
    public void init()
    {
        super();
        QueryBuildDataSource qbdsCustTable,qbdsDirPartyTable;
        qbdsCustTable = CustTable_ds.query().dataSourceTable(tableNum(CustTable));
        qbdsDirPartyTable = qbdsCustTable.addDataSource(tableNum(DirPartyTable));
        qbdsDirPartyTable.addLink(fieldNum(CustTable, Party), fieldNum(DirPartyTable, RecId));
        qbdsDirPartyTable.joinMode(JoinMode::InnerJoin);
    }
}
 
[DataSource]
class LogisticsPostalAddress
{
    public void init()
    {
        super();
        QueryBuildDataSource qbdsDirPartyTable,qbdsLogisticsPostalAddress;
        qbdsDirPartyTable = DirPartyTable_ds.query().dataSourceTable(tableNum(DirPartyTable));
        qbdsLogisticsPostalAddress = qbdsDirPartyTable.addDataSource(tableNum(LogisticsPostalAddress));
        qbdsLogisticsPostalAddress.addLink(fieldNum(DirPartyTable, PrimaryAddressLocation),fieldNum(LogisticsPostalAddress, Location));
        qbdsLogisticsPostalAddress.joinMode(JoinMode::OuterJoin);
    }
}
 
Then I put the fields of DirPartyTable and LogisticsPostalAddress to the form. When I opened the form, I can see the value of DirPartyTable fields but the address fields are blank. Could someone tell me where was wrong?
  • fspafj Profile Picture
    fspafj 207 on at
    Cannot retrieve customer primary address values in form
    Hi Martin,
    Thanks for your response.
    So I removed all the code in the init() method of the data sources and keep data sources properties. However the LogisticsPostalAddress fields are still blank for all customers while they have active primary postal addresses. I did the same query in SQL and it worked fine.
     
    Here is my data source properties:
     
     
     Are you using fields that are populated in the corresponding records in LogisticsPostalAddress?
    -> Im not sure if I understand you correctly but I dragged the fields from LogisticsPostalAddress data source directly into my form.
  • Martin Dráb Profile Picture
    Martin Dráb 230,379 Most Valuable Professional on at
    Cannot retrieve customer primary address values in form
    Throw away all your code, because it's wrong and it's not needed at all. You already created the data sources in form's metadata and there is a QueryBuildDataSource object for each of them. You're adding additional data sources by calling addDataSource(), and you add links to those query data sources created at runtime, not those used by your form data sources. If you needed to make some changes to those data sources in code, you should get references to existing ones by dataSourceTable(), not to create new ones.
     
    So, you don't need code to add data sources. You don't need to set JoinMode either, because it's already done in data sources' properties. You don't need to add a links between tables, because they're created automatically based on existing table relations. Which makes every line of your code obsolete.
     
    Regarding your problem with empty address fields, doesn't it happen to all customers? Do they have postal address valid today? Are you using fields that are populated in the corresponding records in LogisticsPostalAddress? Note that we don't have access to your data and we don't know details of your implementation, therefore our options are limited, but you can do more to analyze the problem.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans