Project Id through X++ code

void clicked()
{
    ProjTable                   projTable;
    ProjInvoiceTable            projInvoiceTable;
    ProjFundingSource           projFundingSource;
    ProjFundingRule             projFundingRule;
    ProjFundingRuleAllocation   projFundingRuleAllocation;
    NumberSeq                   numberSeq,numberSeqInv;
    NumberSequenceFormat        _numberSequenceMask;
    ProjParameters      projParameters  = ProjParameters::find();

    super();

    ttsBegin;
    numberSeq = NumberSeq::newGetNum(ProjParameters::numRefProjId());
    numberSeqInv = NumberSeq::newGetNum(ProjParameters::numRefProjInvoiceProjId());

    projTable.clear();
    projTable.ProjId = numberSeq.num();
    projTable.Name = PropertyTable.Name;
    projTable.Type = ProjType::FixedPrice;
    projTable.ProjGroupId = PropertyTable.ProjGroupId;

    projTable.Format = projParameters.DisplayFormat;

    projInvoiceTable.ProjInvoiceProjId = numberSeqInv.num();
    projInvoiceTable.Description = PropertyTable.Name;
    projInvoiceTable.CurrencyId = CompanyInfo::standardCurrency();

    projFundingSource.ContractId = projInvoiceTable.ProjInvoiceProjId;
    projFundingSource.FundingType = ProjFundingType::Organization;
    projFundingSource.FundingSourceId = PropertyTable.Name;

    projFundingRule.ContractId = projFundingSource.ContractId;
    projFundingRule.Priority = 1;
    projFundingRule.insert();

    projFundingSource.insert();

    projFundingRuleAllocation.AllocateRounding = NoYes::Yes;
    projFundingRuleAllocation.AllocationPercentage = 100;
    projFundingRuleAllocation.FundingRule = projFundingRule.RecId;
    projFundingRuleAllocation.FundingSource = projFundingSource.RecId;
    projFundingRuleAllocation.insert();

    projInvoiceTable.insert();

    projTable.ProjInvoiceProjId = projInvoiceTable.ProjInvoiceProjId;
    projTable.Created = systemDateGet();
    projTable.ValidateProjCategory = NoYes::Yes;
    //Budget control start
    projTable.UseBudgeting = NoYes::Yes;
    projTable.ProjBudgetaryControlOn = ProjBudgetaryControlOn::CostsOnly;
    projTable.ProjBudgetOverrunOption = ProjBudgetOverrunOption::DisallowOverruns;
    projTable.ProjBudgetInterval = ProjBudgetInterval::TotalBudget;
    projTable.ProjCarryForwardRemainingBudget = NoYes::Yes;
    projTable.ProjCarryForwardNegativeBudget = NoYes::Yes;
    //Budget control end
    projTable.insert();

   // PropertyTable.ProjId = projTable.ProjId;
    //PropertyTable.Hierarchy = 1;
    //PropertyTable.update();
    ttsCommit;
    info(strFmt("Project '%1' has been created", projTable.ProjId));
   
}

Comments

Popular posts from this blog

Create RFQ through X++

Base enum values in Dynamics 365