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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Cannot Create purchase requisition through x++ haing a error that the data already exists.

(0) ShareShare
ReportReport
Posted on by 10

Hi,

I was trying to enter a PR after uploading a excel file in D365FO but I am getting an error that the record is already exists.

Here is my snippet of code that I am using.

ttsbegin;

using (ExcelPackage package = new ExcelPackage(Stream))
{
Package.Load(Stream);



worksheet = Package.get_Workbook().get_Worksheets().get_Item(1);
Range = worksheet.Cells;
rowCount = (worksheet.Dimension.End.Row);

//Header
purchReqTable.clear();
purchReqTable.initValue();
purchReqTable.PurchReqId = NumberSeq::newGetNum(PurchReqTable::numRefPurchReqId()).num();
purchReqTable.PurchReqName = range.get_item(4,2).value;
purchReqTable.insert();



if(purchReqTable.validateWrite())
{
//Lines
purchReqTable.insert();
for (row = 8; row <= rowCount;row  )
{
purchReqLine.clear();
purchReqLine.initValue();
purchReqLine.initFromPurchReqTable(purchReqTable);
purchReqLine.ItemId = range.get_item(row,1);
purchReqLine.BuyingLegalEntity = CompanyInfo::find().recId;
PurchReqLine.InventDimIdDataArea = curExt();
purchReqLine.PurchQty = (row,2);
PurchReqLine.modifiedField(fieldNum(purchReqLine,ItemId));



if(purchReqLine.validateWrite())
{
purchReqLine.insert();
}
else
{
throw Error("Requisition Line");
}


}



}
else
{
throw Error("Purchase Requisition Header");
}



info(strFmt("Total %1 purchase requisition(s) uploaded.", Row-1));



ttscommit;
}

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi Jan, 

    You need post the thread to following forum for further help:

    (+) Dynamics 365 Finance - Forums, Blogs, Support

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans