Skip to main content

Notifications

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

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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
    Menna Allah Ahmed 163 on at
    RE: Issue while debugging PO x++

    I changed code with Girish updated also I got this error

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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.

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 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

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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.

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... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans