web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
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();
                        }  

I have the same question (0)
  • Anton Venter Profile Picture
    20,409 Super User 2025 Season 2 on at

    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
    }

  • Menna Allah Ahmed Profile Picture
    163 on at

    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
    20,409 Super User 2025 Season 2 on at

    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
    163 on at

        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
    20,409 Super User 2025 Season 2 on at

    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
    163 on at

    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
    20,409 Super User 2025 Season 2 on at

    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.

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 412 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans