Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

comment code in PurchTable method

(0) ShareShare
ReportReport
Posted on by

Hi Team,

I have debugged cod in PurchTable - setAddressFromInventSiteId()

In this method , I like to comment below code for testing purpose

if (!addressSet)
        {
            companyInfo = CompanyInfo::find();

            location = LogisticsLocationDefault::findSimpleDefault(companyInfo,role).RecId;
            if (location)
            {
                this.setLocation(location, companyInfo);
                addressSet = true;
            }
        }

        return addressSet;

How we can achieve this?

Pls give me more shed on this.

Thanks!

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: comment code in PurchTable method

    The code is different from what I have provided. Please create an extension class and paste as it is.

  • @rp@n Profile Picture
    @rp@n on at
    RE: comment code in PurchTable method

    Hi Mohit,

    public boolean setAddressFromInventSiteId(InventSiteId _inventSiteId)
        {
            next setAddressFromInventSiteId(_inventSiteId);
    
            LogisticsLocationRecId      location;
            InventSite                  inventSite;
            boolean                     addressSet = false;
            CompanyInfo                 companyInfo;
            LogisticsLocationRole       role = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery);
    
            if (this.PurchaseType == PurchaseType::ReturnItem)
            {
                //Never set the address from the site if the purchase order is of type return order.
                return false;
            }
    
            addressSet = this.isDropShipment();
    
            if (!addressSet && _inventSiteId
            && !this.InterCompanyDirectDelivery)
            {
                inventSite = InventSite::find(_inventSiteId);
                location   = LogisticsLocationDefault::findSimpleDefault(InventSite::find(_inventSiteId), role).RecId;
    
                if (location)
                {
                    this.setLocation(location, inventSite);
                    addressSet = true;
                }
            }
    
            /*
            if (!addressSet)
            {
                companyInfo = CompanyInfo::find();
    
                location = LogisticsLocationDefault::findSimpleDefault(companyInfo,role).RecId;
                if (location)
                {
                    this.setLocation(location, companyInfo);
                    addressSet = true;
                }
            }
            */
    
            return addressSet;

    This code is NOT returning any error.

    Pls give me more shed on this.

    thanks!

  • @rp@n Profile Picture
    @rp@n on at
    RE: comment code in PurchTable method

    Hi Mohit, 

    I tried the code and got below issue

    pastedimage1682487802104v1.png

    Pls give me more shed on this.

    thanks!

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: comment code in PurchTable method

    Hi, You can't change standard code but can manipulate (By pass) it. I tried to create the code snippet for you, please check and let me know if any issues. You need to be aware that if Microsoft updates code in standard setAddressFromInventSiteId method in future, you have to update it in your extended code as well. 

    [ExtensionOf(tableStr(PurchTable))]
    internal final class PurchTable_T_Extension
    {
        public boolean setAddressFromInventSiteId(InventSiteId _inventSiteId)
        {
            LogisticsLocationRecId      location;
            InventSite                  inventSite;
            boolean                     addressSet = false;
            CompanyInfo                 companyInfo;
            LogisticsLocationRole       role = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery);
           
            PurchaseType purchaseTypeLocal = this.PurchaseType;
    
            if (this.PurchaseType != PurchaseType::ReturnItem)
            {
                purchaseTypeLocal = this.PurchaseType;
                this.PurchaseType = PurchaseType::ReturnItem;
            }
    
            addressSet = next setAddressFromInventSiteId(_inventSiteId); 
    
            if (purchaseTypeLocal != PurchaseType::ReturnItem)
            {
                this.PurchaseType = purchaseTypeLocal;
    
                addressSet = this.isDropShipment();
    
                if (!addressSet && _inventSiteId && !this.InterCompanyDirectDelivery)
                {
                    inventSite = InventSite::find(_inventSiteId);
                    location   = LogisticsLocationDefault::findSimpleDefault(InventSite::find(_inventSiteId), role).RecId;
    
                    if (location)
                    {
                        this.setLocation(location, inventSite);
                        addressSet = true;
                    }
                }
    
                //if (!addressSet)
                //{
                //    companyInfo = CompanyInfo::find();
    
                //    location = LogisticsLocationDefault::findSimpleDefault(companyInfo,role).RecId;
                //    if (location)
                //    {
                //        this.setLocation(location, companyInfo);
                //        addressSet = true;
                //    }
                //}
    
            }
    
            return addressSet;
        }
    
    }

  • @rp@n Profile Picture
    @rp@n on at
    RE: comment code in PurchTable method

    Hi Andre, as per my requirement,  I have to skip those code . As you said, its wont possible then how can I make this possible?

    Kindly give me some solution pls

    Pls give me more shed on this

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,162 Super User 2025 Season 1 on at
    RE: comment code in PurchTable method

    Hi Arpan,

    You can't skip coding in a CoC method. You can only add additional logic and influence a possible return value.

    If you need a temporary change for testing or debugging purposes only, you can relax the model to (temporary) allow overlayering, so you can out comment code as you need. See the next page on Microsoft Learn.

    Relax model restrictions to refactor overlayering into extensions - Finance & Operations | Dynamics 365 | Microsoft Learn

  • @rp@n Profile Picture
    @rp@n on at
    RE: comment code in PurchTable method

    I like to declare flag = false;

    If (flag == false)

    {

       Like to skip the code above mentioned from the method setAddressFromInventSiteId() through CoC

    }

    Pls give me more shed on this

  • @rp@n Profile Picture
    @rp@n on at
    RE: comment code in PurchTable method

    I know, can you give me one example of sample code pls

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: comment code in PurchTable method

    Please read my earlier comment again.

  • @rp@n Profile Picture
    @rp@n on at
    RE: comment code in PurchTable method

    The method is SetAdddressfromInventSiteId from PurchTable already mentioned.

    The code which I mentioned only  like to skip from the method SetAddressfromInventSiteId through CoC that's it.

    Let t me know how will acheive this?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans