Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Create Project through x++

$
0
0

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.Description;
    //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?


Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>