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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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



}

I have the same question (0)
  • Martin Dráb Profile Picture
    237,783 Most Valuable Professional on at

    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

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 692 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 364 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans