Hello All,
I would like to create a project using x++ in 2012 R2.
First I've made a class that create a project contract using the following code,
str ContCr(str CustAcc) { ProjInvoiceTable projInvoiceTable; CustTable custTable; CustAccount custAccount; ProjFundingSource projFundingSource; NumberSeq numSeq; info("Project contract is being created"); ttsbegin; projInvoiceTable.clear(); projInvoiceTable.initValue(); custTable = CustTable::find(CustAcc); numSeq = NumberSeq::newGetNum(ProjParameters::numRefProjInvoiceProjId(),true,true); projInvoiceTable.ProjInvoiceProjId = numSeq.num(); projInvoiceTable.CurrencyId = "EGP"; projInvoiceTable.Description = custTable.name(); projInvoiceTable.insert(); info("projInvoiceTable.ProjInvoiceProjId: " + projInvoiceTable.ProjInvoiceProjId); projFundingSource.ContractId = projInvoiceTable.ProjInvoiceProjId; projFundingSource.CustAccount = CustAcc; projFundingSource.FundingSourceId = custTable.name(); projFundingSource.FundingType = ProjFundingType::Customer; projFundingSource.editProjFunder(true,projFundingSource.CustAccount); projFundingSource.insert(); projFundingRule::createDefaultFundingRule(projInvoiceTable.ProjInvoiceProjId, projInvoiceTable.RecId); ttscommit; return projInvoiceTable.ProjInvoiceProjId; }
It works successfully, But as a return of this contract I'm trying to create the project itself using the following code,
void clicked() { ProjInvoiceTable projInvoiceTable; ProjTableType projTableType; NumberSeq projNumberSeq; ProjId projIdLastSon, projectId; ProjTable projTable; ProjId projMask; ProjName _projName; Integer sonNum; ProjType _projType; ProjGroupId _projGroupId; ProjInvoiceProjId _projInvoiceProjId; ProjLinePropertyId _projInvoiceStatusId; str ContID; super(); ContID = this.ContCr("0006-Custom"); _projType = ProjType::TimeMaterial; //1# _projGroupId = 'T&M'; _projName = "Proj-Test"; //2# _projInvoiceProjId = ContID; projTable.ProjId = '19992'; projectId = projTable.ProjId; projTable.Type = _projType; projTable.ProjGroupId = _projGroupId; projTable.Name = _projName; projTableType = projTable.type(); projTableType.initProjTable(); projTable.ProjInvoiceProjId = _projInvoiceProjId; projInvoiceTable = ProjInvoiceTable::find(_projInvoiceProjId); projTable.CustAccount = projInvoiceTable.Name; projTable.initFromInvoice(projInvoiceTable); //projTable.Format = _numberSequenceMask; projTable.CheckBudget = ProjGroup::find(_projGroupId).CheckBudget; if (_projInvoiceStatusId) { ProjLinePropertySetup::updateLinePropertyProj(projTable.ProjId, _projInvoiceStatusId, TableGroupAll::Table, true); } projTable.initFromCustTable(CustTable::find(projTable.CustAccount)); if (ProjTable::exist(projTable.ProjId)) { // Project already exists. throw error("@SYS56494"); } if (!projTableType.validateWrite()) throw error ("Validations failed"); projTable.insert(); if (projNumberSeq) { projNumberSeq.used(); } else { projTable.clear(); if (projNumberSeq) { projNumberSeq.abort(); } } info (strfmt('Project %1 successfully created ', projectId)); }
Project is successfully created but all customer information is not provided to the project.
any help?
*This post is locked for comments
BTW I've got this code from
dynamicsaxgyan.wordpress.com/.../create-projects-or-sub-projects-using-x-dynamics-ax
But I only wants to create a project with no sub projects so I've tried to modify the code
Actually no, The error is not related to the project id as it not exist and when I run this code it creates it but with no customer data
But if I added the following line
projTable.CustAccount = "0006-Custom";
Project is not created and give me this error
Cannot create a record in Locations (LogisticsLocation). Location ID: 000002339, Custom - Ahmed Awwad.
The record already exists.
That's because you cannot have 2 projects with the same id and you have it hardcoded
projTable.ProjId = '19992';
Either change it or delete existing project.
You are totally right I was testing and forget to return code back.
Original code was
projTable.CustAccount = projInvoiceTable.Name
But it returns nothing because projInvoiceTable doesn't have name.
Anyway for testing purpose I've provided the customer account manually like
projTable.CustAccount = "0006-Custom";
but It gives me error says something like record already exist
I will provide the full screenshot for the error once I be in this location tomorrow morning.
But seems like this code was not for R2 :(
Hi Ahmed Awwad,
Are you sure that
CustTable::find(projTable.CustAccount)
returns you custTable ? Because you initiliaze projTable.CustAccount with projInvoiceTable.Description that does not make a lot of sense.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,817
Most Valuable Professional
nmaenpaa
101,156