Skip to main content

Notifications

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

While import salesline data through data entity need to create purchase order from sales order.

(0) ShareShare
ReportReport
Posted on by 45

While importing sales order using the custom entity, if the last sales order line is created,
new purchase order will be created for the sales lines which having the ‘Auto created
purchase order’ setup in Item master. The PO should be auto confirmed.

ï‚· Even if one sales order line does not have a primary vendor associated with the item, then
the PO should not be created, and the details will get stored to the error log table. 

this is my requirement

public static void postTargetProcess(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
{
PurchCreateFromSalesOrder purchCreateFromSalesOrder;
PurchAutoCreate purchAutoCreate;
NumberSeq numberSeq;
TmpPurchLinePrice tplP;
VendAccount prevVendAccount;
InventTableModule inventTableMod;
SalesTable salesTable;
SalesLine salesLine;
PurchTable purchTable;
InventTable inventTable;
DirPartyTable party;
CustTable custTable;
IMPDAutoPOErrors autoPoErrors;
LineNum lineNumber = 0;
IMPDSalesLineStaging salesLineStaging;
NoYesId noyes;

DMFDefinitionGroupName definitionGroup = _dmfDefinitionGroupExecution.DefinitionGroup;
DMFExecutionId executionId = _dmfDefinitionGroupExecution.ExecutionId;
DMFEntityName entityName = _dmfDefinitionGroupExecution.Entity;
DMFDefinitionGroupExecution currentExecution;

if (_dmfDefinitionGroupExecution.StagingStatus == DMFBatchJobStatus::Finished)
{



ttsbegin;
while select salesLineStaging
where salesLineStaging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup
&& salesLineStaging.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId
&& salesLineStaging.TransferStatus == DMFTransferStatus::Completed
{



while select SalesId from salesLineStaging
group by SalesId
where salesLineStaging.DefinitionGroup == definitionGroup
&& salesLineStaging.ExecutionId == executionId
{
salesTable = SalesTable::find(salesLineStaging.SalesId);

if(salesTable)
{

while select salesLine
order by inventTable.PrimaryVendorId
where salesLine.SalesId == salesTable.SalesId
join inventTable
where inventTable.ItemId == salesLine.ItemId
join inventTableMod
where inventTableMod.ItemId == inventTable.ItemId
{
if ( !inventTable.PrimaryVendorId)
{
numberSeq=NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numberSeq.used();
purchTable.PurchId = numberSeq.num();



autoPoErrors.PurchaseOrder = purchTable.PurchId;
autoPoErrors.SalesOrder = salesLine.SalesId;
autoPoErrors.ItemNumber = salesLine.ItemId;
autoPoErrors.insert();
delete_from tplP;
lineNumber = 0;
}

salesTable = salesLine.salesTable();

tplP.clear();
lineNumber  = 1;
tplP.SalesId = salesLine.SalesId;
tplP.LineNum = lineNumber;
tplP.SalesLineRefRecId = salesLine.RecId;
tplP.AccountNum = inventTable.PrimaryVendorId;

tplP.ItemId = salesLine.ItemId;
tplP.InventDimId = salesLine.InventDimId;

tplP.Included = NoYes::Yes;

tplP.PurchQty = salesLine.SalesQty;
tplP.QtyOrdered = salesLine.QtyOrdered;

tplP.PurchUnit = salesLine.SalesUnit;
tplP.LineAmount = salesLine.LineAmount;

tplP.LineDisc = salesLine.LineDisc;
tplP.LinePercent = salesLine.LinePercent;
tplP.MultiLineDisc = salesLine.MultiLnDisc;
tplP.MultiLinePercent = salesLine.MultiLnPercent;

//tplP.Price = salesLine.SalesPrice;
tplP.PriceUnit = salesLine.PriceUnit;
tplP.CurrencyCode = salesLine.CurrencyCode;

tplP.Markup = salesLine.SalesMarkup;

tplP.insert();

prevVendAccount = tplP.AccountNum;
noyes =inventTableMod.AutoCreatePurchaseOrder;

if (prevVendAccount && salesTable.SalesStatus == SalesStatus::Backorder )
{
purchAutoCreate = PurchAutoCreate::construct(tplP,PurchCreateFromSalesOrder);
purchAutoCreate.create();
delete_from tplP;


}
}
}


}
}
ttscommit;
}



}

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: While import salesline data through data entity need to create purchase order from sales order.

    Please describe your problem. "this code is not working" might mean anything.

    Post your code with line indentation - your current version is very difficult to follow. Always use Insert > Code (in the rich formatting view) to paste source code to this forum.

    By the way, I moved your question from the AX forum, because I think it's actually about F&O.

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans