Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

method that create or update accounting distribution on PO after changing line property x++

(0) ShareShare
ReportReport
Posted on by 163

we create a customization button that change line property of all lines on PO then create or update accounting distribution but not working if PO credit line 

which method should I call to fix this ? 

fix that accounting distribution doesn't update if we click on this button in credit note case 

when we click on this button will change line property so what's missing to work all logic of accounting distribution 

  select forupdate _PurchLine where _PurchLine.PurchId == PurchTable.PurchId;
                        if (_PurchLine)
                        {
                            _PurchLine.ProjLinePropertyId = 'Noncharge';
                            purchLineType = _PurchLine.type();
                            _PurchLine.update();
                        }  

  • Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

    The way I see it and without investigating this in the system, is the accounting distribution is following the setup/configuration to determine which main/ledger account to use.

    You will have to check the code of the accounting distribution to see how it's choosing the ledger/main accounts.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

    when line property changing account distribution created , I need to know why account distribution created 3 lines with the same main account 

  • Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

    In your code, I see the line property of all order lines being changed to 'Noncharge'. What do you expect to happen? What are the requirements?

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

        public static void main(Args args)
        {
            if (args)
            {
                PurchTable PurchTable, _PurchTable;
                PurchLine PurchLine, _PurchLine ,_purchLineOrig;
                AllowCustomerInvoice  AllowCustomerInvoice;
                FormRun PurchForm = args.caller();
               FormDataSource PurchLine_DS;
                DialogButton diagBut;
                purchLineType  purchLineType;
    
                str strMessage = "Are you sure you want to allow customer invoice?";
                str strTitle = "Allow Customer Invoice";
             
                diagBut = Box::yesNo(strMessage, DialogButton::Yes, strTitle);
    
                if(diagBut == DialogButton::No)
                {
                    //your own code when user click on No button
                    return;
                }
    
               else if(diagBut == DialogButton::Yes)
                {
                    //your own code when user click on Yes button
                    select * from PurchTable
                    where PurchTable.RecId == args.record().RecId;
    
                    while select PurchLine
                    where PurchLine.PurchId == PurchTable.PurchId
                         && PurchLine.PurchStatus != PurchStatus::Invoiced
                        && PurchLine.PurchStatus != PurchStatus::Canceled
                    {
                        ttsbegin;
                        select forupdate AllowCustomerInvoice
                            where AllowCustomerInvoice.PurchLine == PurchLine.RecId;
    
                        if(AllowCustomerInvoice)
    					{
                            AllowCustomerInvoice.AllowInvoice = NoYes::Yes;
                            AllowCustomerInvoice.update();
                    
    					}
                        else
    					{
                        AllowCustomerInvoice.PurchLine = PurchLine.RecId;
                        AllowCustomerInvoice.AllowInvoice = NoYes::Yes;
                        AllowCustomerInvoice.insert();
    
                       }
                        
                        ttscommit;
    
    
                 
                        ttsBegin;
                        
                        if(PurchTable.DocumentState ==VersioningDocumentState::Draft)
                        {
                          while  select forupdate _PurchLine 
                          where _PurchLine.PurchId == PurchTable.PurchId
                          {
                           
                                _PurchLine.ProjLinePropertyId = 'Noncharge';
                                purchLineType = _PurchLine.type();
                                _PurchLine.update();
                            
                            
                        }
                        
                        }
                        else
                        {
                            select  forupdate _PurchTable   where _PurchTable.PurchId == PurchTable.PurchId;
                            _PurchTable.DocumentState = VersioningDocumentState::Draft;
                            _PurchTable.doUpdate();
    
                          while  select forupdate _PurchLine
                          where _PurchLine.PurchId == PurchTable.PurchId
                          {
                          
                                _PurchLine.ProjLinePropertyId = 'Noncharge';
                                purchLineType = _PurchLine.type();
                                _PurchLine.update();
    
                            
    
                            _PurchTable.DocumentState = PurchTable.DocumentState;
                            _PurchTable.doUpdate();
                        
                        }
    
                        ttsCommit;
                        //
    
    
                    }
                 
        
                }
                
               Info("Done");
            }
             
        }

  • Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

    By updating the lines to non billable, those lines will not get invoiced. The way I see it and without investigating this in the system, is the accounting distribution is following the setup/configuration to determine which main/ledger account to use. Perhaps if you share more of your code we can help you better.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

    I change code to while select but still I have the same issue , accounting distribution create 2 lines with the same main account so that's wrong , why update of tables doesn't work well , the main code in these two lines we update this if button of allow customer invoice check we update line property to noncharge if we click on dis allow customer we change line property to line property of category (get the main line of category) and we called update in two cases

  • Anton Venter Profile Picture
    Anton Venter 19,493 Super User 2025 Season 1 on at
    RE: method that create or update accounting distribution on PO after changing line property x++

    The first question: from what I can see from your code, your code selects a single line from the order and only updates the line property of that line only. So it's not updating all lines in the order. To update all lines, you have to use a "while select" statement to select all lines from the order.

    As for the rest of your questions, you will have to share the code here so that we can try to see what's wrong.

    By the way, I recommend you use different variables for updating the table(s) in question. You are updating the _purchLine table buffer variable passed to your method. This could lead to unwanted behaviour if you are passing a table buffer from a form datasource for example. Also, do not use hard coded values in the code, instead use a parameter table for that.

    PurchLine purchLine;
    
    while select forUpdate purchLine
        where purchLine.PurchId == _purchTable.PurchId
    {
        //do something here
    }

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,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans