Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Global address book

Posted on by Microsoft Employee

1. Delete un-matched location
    while select forupdate inventLocationLogisticsLocation
        where inventLocationLogisticsLocation.InventLocation == sInventLocation.RecId
    notexists join dirPartyLocation
        where dirPartyLocation.Location == inventLocationLogisticsLocation.Location
           && dirPartyLocation.Party == this.OMOperatingUnitID
    {
        deletePostalAddress = LogisticsPostalAddress::findByLocation(inventLocationLogisticsLocation.Location, true);
        if (deletePostalAddress.RecId)
            if (deletePostalAddress.aosValidateDelete())
                deletePostalAddress.delete();
        inventLocationLogisticsLocation.delete();
    }
 2. Update matched location
    while select forUpdate inventLocationLogisticsLocation
        where inventLocationLogisticsLocation.InventLocation == sInventLocation.RecId
    join  dirPartyLocation
        where dirPartyLocation.Location == inventLocationLogisticsLocation.Location
            && dirPartyLocation.Party == this.OMOperatingUnitID
    join logisticsPostalAddress
        where logisticsPostalAddress.Location == dirPartyLocation.Location
    {
        rolesCon = _rolesMap.lookup(dirPartyLocation.Location);
        inventLocationLogisticsLocation.InventLocation = sInventLocation.RecId;
        inventLocationLogisticsLocation.Location = dirPartyLocation.Location;
        inventLocationLogisticsLocation.IsPrimary = dirPartyLocation.IsPrimary;
        inventLocationLogisticsLocation.IsPrivate = logisticsPostalAddress.IsPrivate;
        inventLocationLogisticsLocation.addEntityLocation(rolesCon, true);
        inventLocationLogisticsLocation.update();
    }
 3. Insert new location
    while select  dirPartyLocation
        where dirPartyLocation.Party == this.OMOperatingUnitID
    notExists join inventLocationLogisticsLocation
        where inventLocationLogisticsLocation.InventLocation == sInventLocation.RecId
            && inventLocationLogisticsLocation.Location == dirPartyLocation.Location
    notexists join  logisticsPostalAddress
        where logisticsPostalAddress.Location == dirPartyLocation.Location
    {
        rolesCon = _rolesMap.lookup(dirPartyLocation.Location);
        //Create new location
        newLogisticsLocation = LogisticsLocation::create(LogisticsLocation::find(dirPartyLocation.Location).Description);

 

        //Create address
        newPostalAddress.clear();
        newPostalAddress.data(logisticsPostalAddress::findByLocation(dirPartyLocation.Location));
        newPostalAddress.Location = newLogisticsLocation.RecId;
        newPostalAddress.insert();
       //Create mapping
        newInventLocationLogisticsLocation.clear();
        newInventLocationLogisticsLocation.InventLocation = sInventLocation.RecId;
        newInventLocationLogisticsLocation.Location = newLogisticsLocation.RecId;
        newInventLocationLogisticsLocation.IsPrimary = dirPartyLocation.IsPrimary;
        newInventLocationLogisticsLocation.IsPrivate = logisticsPostalAddress.IsPrivate;
        newInventLocationLogisticsLocation.insert();
        newInventLocationLogisticsLocation.addEntityLocation(rolesCon, true);
    }
    ttsCommit;

I am using the joins above for inserting ,deleting and updating the address in retain channel and in the warehouse.

It is working fine for me in DEV and in QA but  when I ran the same piece code in PROD it is killing the performance and it is taking almost 6-7 mins to update/insert/delete.

Categories:
  • Suggested answer
    Rachit Profile Picture
    Rachit 4,011 User Group Leader on at
    RE: Global address book

    You can create it as a batch task and use multithreading to improve the performance.

    microsoft-dynamics-ax-erp.blogspot.com/.../batch-parallelism-in-ax-part-i.html

  • Suggested answer
    greengrimms Profile Picture
    greengrimms 1,400 on at
    RE: Global address book

    Hi,

    As previously suggested, use trace parser in order to find out where the query is having problems.

    I suggest taking the trace on prod (or any other environment where you can replicate this), downloading it in your dev vm and then importing it there to the Dynamics 365 Trace Parser tool. Then you can take the trace, and sort the SQL queries by execution time and see which one is causing trouble. After that, you can take the query and run the Execution plan in SQL in a lower tier environment.

    Also if I may suggest, get a copy of the prod database to a lower tier environment for easier testing/debugging.

    Good luck and feel free to reach out.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 288,420 Super User on at
    RE: Global address book

    Hi mahiims18,

    Did you test in DEV and QA with the same data and security roles? How many records are involved? If so, you have to start monitoring what might be wrong. You can check for fragmented or missing indexes. You can also use the Trace parser and check which part of the execution is causing the delays.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans