My code here is to copy Purchase Agreement line from reference Purchase Agreement to new Purchase Agreement.
static void PSMCopydirecttoagreementline(Args _args)
{
AgreementLineQuantityCommitment agreementLineQuantity;
AgreementLineQuantityCommitment xagreementLineQuantity;
AgreementLineVolumeCommitment agreementlinevolume;
AgreementLineVolumeCommitment xagreementlinevolume;
PurchAgreementHeader purchAgreementHeader = PurchAgreementHeader::findAgreementId("PSM-000020");//Header reference
purchAgreementHeader xpurchagreementheader = PurchAgreementHeader::findAgreementId("PSM-000078");//Header baru
//Jika Komitment Purchase Agreement berdasaran kuantity
if(purchAgreementHeader.DefaultAgreementLineType == CommitmentType::ProductQuantity)
{
info("Quantity based");
//copy line AgrementLIneQuanity menjadi line baru
while select agreementLineQuantity
where agreementLineQuantity.Agreement == purchAgreementHeader.RecId
{
xagreementLineQuantity.clear();
xagreementLineQuantity.data(agreementLineQuantity);
xagreementLineQuantity.Agreement = xpurchagreementheader.RecId;
xagreementLineQuantity.doInsert();
}
}
else
{
//Jika Komitment Purchase Agreement BUKAN berdasaran kuantity
info("value based");
while select agreementlinevolume
where agreementlinevolume.Agreement == purchAgreementHeader.RecId
{
xagreementlinevolume.clear();
xagreementlinevolume.data(agreementlinevolume);
xagreementlinevolume.Agreement = xpurchagreementheader.RecId;
xagreementlinevolume.doInsert();
}
}
}
below is how to setup and create new Purchase Agreement(header) from reference Purchase Agreement(header) through x++
void createDuplicate()
{
ttsBegin;
this.setHeader();
this.createPurchAgreementHeader();
this.setLine();
//this.createAgreementLine();
ttsCommit;
info("done");
}
void setHeader()
{
PurchAgreementId tmpAgreementId;
NumberSeq num;
xpurchagreementheader.clear();
xpurchagreementheader.data(purchAgreementHeader);
xpurchagreementheader.WorkflowStatus_PSN = PurchAgreementWorkflowStatus::NotSubmitted;
xpurchagreementheader.PSMTotalNetAmount = 0;
num = NumberSeq::newGetNum(PurchParameters::numRefPurchAgreementId());
tmpAgreementId = num.num();
info(strFmt("num %1",tmpAgreementId));
if (PurchAgreementHeader::findAgreementId(tmpAgreementId).RecId)
{
num.abort();
checkFailed("@SYS19304");
checkFailed(strfmt("@SYS24176", tmpAgreementId));
throw error("@SYS23020");
}
xpurchagreementheader.PurchNumberSequence = tmpAgreementId;
num.used();
agreementHeaderDefault = AgreementHeaderDefault::findAgreementHeader(purchAgreementHeader.RecId);
if(agreementHeaderDefault.RecId)
{
xgreementHeaderDefault.clear();
xgreementHeaderDefault.data(agreementHeaderDefault);
}
purchAgreementHeaderDefault = PurchAgreementHeaderDefault::findPurchAgreementHeader(purchAgreementHeader.RecId);
if(purchAgreementHeaderDefault.RecId)
{
xpurchAgreementHeaderDefault.clear();
xpurchAgreementHeaderDefault.data(purchAgreementHeaderDefault);
}
void createPurchAgreementHeader()
{
xpurchagreementheader.insert();
xgreementHeaderDefault.AgreementHeader = xpurchagreementheader.RecId;
xgreementHeaderDefault.insert();
xpurchAgreementHeaderDefault.PurchaseAgreementHeader = xpurchagreementheader.RecId;
xpurchAgreementHeaderDefault.insert();
}
note :
u must define/create those 3 method createDuplicate(),setHeader() and createPurchAgreementheader() in the class. for me i called those three methods in run() method.
All Archives in this blog may be used for the Junior,Dummies or someone who just started for career at Dynamics Ax ... A Place Where U can Start ur Code - right here ...
Langganan:
Posting Komentar (Atom)
Erorr CS1963 - An expression tree may not contain a dynamic operation.
Kali ini saya mendapatkan erorr dengan code CS1963, padahal sebelumnya saya sudah mendefinisikan 'var item in Model' di @foreach(var...
-
My code here is to copy Purchase Agreement line from reference Purchase Agreement to new Purchase Agreement. static void PSMCopydirecttoag...
-
If you want to try custom your notification, AX Standard can bring the user to the form where the information exist but when the form was...
-
"Error while setting server report parameters. Error Message: The item ´/DynamicsAx/PurchPurchaseOrderreport.Report4´ cannot be found ...
Tidak ada komentar:
Posting Komentar