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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Create Project through x++

(0) ShareShare
ReportReport
Posted on by 85

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

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    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.

  • Ahmed Awwad Profile Picture
    85 on at

    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 :(

  • Mea_ Profile Picture
    60,286 on at

    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.

  • Ahmed Awwad Profile Picture
    85 on at

    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.

  • Ahmed Awwad Profile Picture
    85 on at

    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

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

News and Announcements

Season of Giving Solutions is Here!

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 AX (Archived)

#1
TAHER Mehdi Profile Picture

TAHER Mehdi 3

#2
Nakul Profile Picture

Nakul 2

#2
Mea_ Profile Picture

Mea_ 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans