Saturday, March 6, 2021

transaction scope is expected from the caller of method salesline.insert dynamics 365 x++

 I was getting the below error while creating return order lines.

transaction scope is expected from the caller of method salesline.insert.


Solution: Usually you get this error when your code is not in transaction begin and commit.

Write your code between ttsbegin and ttscommit


Ex: 

                                ttsbegin;

                                salesLine.initFromSalesTable(_retOrdSalesTable);

                                salesLine.ItemId        = itemId;

                                salesLine.SalesUnit     = InventTableModule::find(itemId, ModuleInventPurchSales::Invent).UnitId;

                                salesLine.SalesPrice    = unitPrice;

                                if(salesLine.SalesPrice == 0.00)

                                {

                                    inventDimPrice.clear();

                                    inventDimPrice.InventSiteId = inventSiteId;

                                    inventDimPrice = InventDim::findOrCreate(inventDimPrice);

                                    salesLine.setPriceAgreement(inventDimPrice);

                                }

                                salesLine.LineAmount    = salesLine.calcLineAmount();

                                salesLine.SalesQty      = 0;

                                inventBatch = InventBatch::find('999', itemId);

                                if(!inventBatch)

                                {

                                    select firstfast inventBatch order by

                                         createdDateTime desc  where inventBatch.itemId == itemId

                                            && inventBatch.inventBatchId    != '';

                                }

                                inventDimGet.InventLocationId = inventLocationId;

                                inventDimGet.InventSiteId     = inventSiteId;

                                inventDimGet.wMSLocationId    = wMSLocationId;

                                inventDimGet.inventBatchId    = inventBatch.inventBatchId;


                                inventDimGet = InventDim::findOrCreate(inventDimGet);

                                // find inventDim

                                salesLine.InventDimId   = inventDimGet.inventDimId;

                                salesLine.createLine(true, true, true, false, false, false, false, false);

                                

                                salesLine.selectForUpdate(true);

                                salesLine.ExpectedRetQty = -qty;

                                salesLine.update();

                                ttscommit;

1 comment:

  1. The 10 Best Casinos In Las Vegas (2021) - Mapyro
    Casinos 충청남도 출장마사지 Near Harrah's 통영 출장샵 Casino in Las 정읍 출장마사지 Vegas 부천 출장마사지 (2021). Where: 777 Harrah's Blvd, Las Vegas, NV 89109. 천안 출장안마 Phone: (702) 770-7777.

    ReplyDelete

Why do users often get confused about Dynamics 365 Customer Engagement (D365 CE), Dataverse, and the Power Platform?

  The Microsoft ecosystem for business applications can sometimes be difficult to navigate, especially when discussing Dynamics 365 Customer...