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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Issue while debugging PO x++

(0) ShareShare
ReportReport
Posted on by 163

we created a new controls (allow customer invoice , dis allow customer invoice ) 

allow customer invoice change value of line property of category in PO to be nonchargeable (if chargeable set it noncharge ) and dis allow customer invoice gets value of line property from category and set it in line property in PO 

I tried to debug update in purch line table after changing this values but I got this error I tried to build model and sync database but no thing is working 

This is our code in class allow customer invoice :

public class AllowCustomerInvoiceCFM  extends RunBase
{
    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;

                    
                    if(PurchTable.DocumentState ==VersioningDocumentState::Draft)
                    {
                        select forupdate _PurchLine where _PurchLine.PurchId == PurchTable.PurchId;
                        if (_PurchLine)
                        {
                            _PurchLine.ProjLinePropertyId = 'Noncharge';
                            purchLineType = _PurchLine.type();
                            ttsBegin;
                            _PurchLine.update();
                            ttsCommit;

                        }  
                    }
                    else
                    {
                        select  forupdate _PurchTable   where _PurchTable.PurchId == PurchTable.PurchId;
                        _PurchTable.DocumentState = VersioningDocumentState::Draft;
                     
                        ttsBegin;
                        _PurchTable.doUpdate();
                        ttsCommit;

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

                        }

                        _PurchTable.DocumentState = PurchTable.DocumentState;
                        ttsBegin;
                        _PurchTable.doUpdate();
                        ttsCommit;

                    }

                }
            
            }
            
           Info("Done");
        }
         
    }

}

How can I fix this issue ? Its a cloud environment with version 33

I have the same question (0)
  • Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Issue while debugging PO x++

    Hi Menna, Can you try commenting all ttsBegin and ttscommit in your code and add just one ttsBegin in the beginning and ttsCommit in the end of main method of your class.

  • Menna Allah Ahmed Profile Picture
    163 on at
    RE: Issue while debugging PO x++

    Hi Mohit , it was one ttsbegin and one ttscommit and still the same error , I saw this solution to put them before and after update of tables so I change them

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at
    RE: Issue while debugging PO x++

    You need to encapsulate the update method with ttsbegin and ttscommit.

    Try the below code and check if it works.

    public class AllowCustomerInvoiceCFM  extends RunBase
    {
        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
                    {
                        
                        select forupdate AllowCustomerInvoice
                            where AllowCustomerInvoice.PurchLine == PurchLine.RecId;
    
                        if(AllowCustomerInvoice)
    					{
    					    ttsbegin;
                            AllowCustomerInvoice.AllowInvoice = NoYes::Yes;
                            AllowCustomerInvoice.update();
                            ttscommit;
                    
    					}
                        else
    					{
                        AllowCustomerInvoice.PurchLine = PurchLine.RecId;
                        AllowCustomerInvoice.AllowInvoice = NoYes::Yes;
                        AllowCustomerInvoice.insert();
    
                       }
                        
                        
    
                        
                        if(PurchTable.DocumentState ==VersioningDocumentState::Draft)
                        {
                            select forupdate _PurchLine where _PurchLine.PurchId == PurchTable.PurchId;
                            if (_PurchLine)
                            {
                                _PurchLine.ProjLinePropertyId = 'Noncharge';
                                purchLineType = _PurchLine.type();
                                ttsBegin;
                                _PurchLine.update();
                                ttsCommit;
    
                            }  
                        }
                        else
                        {
                            select  forupdate _PurchTable   where _PurchTable.PurchId == PurchTable.PurchId;
                            _PurchTable.DocumentState = VersioningDocumentState::Draft;
                         
                            ttsBegin;
                            _PurchTable.doUpdate();
                            ttsCommit;
    
                            select forupdate _PurchLine where _PurchLine.PurchId == PurchTable.PurchId;
                            if (_PurchLine)
                            {
                                _PurchLine.ProjLinePropertyId = 'Noncharge';
                                purchLineType = _PurchLine.type();
                                
                                ttsBegin;
                                _PurchLine.update();
                                ttsCommit;
    
                            }
    
                            _PurchTable.DocumentState = PurchTable.DocumentState;
                            ttsBegin;
                            _PurchTable.doUpdate();
                            ttsCommit;
    
                        }
    
                    }
                
                }
                
               Info("Done");
            }
             
        }
    
    }

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Issue while debugging PO x++

    In your code, ttsbegin at Line# 37 is added inside while select statement and ttscommit is added outside the loop at line# 55. You can try moving ttsBegin to line 31.

  • Menna Allah Ahmed Profile Picture
    163 on at
    RE: Issue while debugging PO x++

    I changed code with Girish updated also I got this error

  • GirishS Profile Picture
    27,827 Moderator on at
    RE: Issue while debugging PO x++

    Seems it's a synch error. Is SourceDocumentLineImplementation custom table or standard table. Try a full DB Synchronization and check.

    Seems it's a custom table.

    Thanks,

    Girish S.

  • Menna Allah Ahmed Profile Picture
    163 on at
    RE: Issue while debugging PO x++

    it is not a custom table I tried to sync and not working , now I am getting this error also

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

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
Martin Dráb Profile Picture

Martin Dráb 724 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 400 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans