RE: update line quantity using x++ code
Hello Dineshkarlekar,
You don't really need a form that is called Dialog for this. You can just create dialog-type object on the go within a job or a class.
learn.microsoft.com/.../using-classes-to-create-a-dialog
So at first you initialize your dialog fields. It seems you need purchId entered by the user - so you just need that field and line number then.
It is hard to tell what exactly you are trying to update in the end from your explanation - but I assume it is PurchQty field. You can replace that bit in your code with what you need. If you are trying to update delivry reminder - there is a standard AX 2012 function for that, too.
So the code below should get you closer to what you wanted (this is AX 2012 Job object):
static void community_forum_468941(Args _args)
{
PurchLine purchLine;
Dialog dialog = new Dialog();
DialogField dialogFieldPOid, dialogPOLineNum;
LineNum purchLineNum;
PurchId purchOrderNum;
;
//we create a Dialog object first and initialize fields there
dialog.caption("Update PO record");
dialogFieldPOid = dialog.addField(extendedTypeStr(PurchId),"Purchase order to check");
dialogPOLineNum = dialog.addField(extendedTypeStr(LineNum),"PO line number to check");
//then, we check if OK or Cancel was pressed and if OK, proceed to the logic
if(dialog.run())
{
//grabbing user-entered values from Dialog fields
purchOrderNum = dialogFieldPOid.value();
purchLineNum = dialogPOLineNum.value();
//working on the actual update - creating transaction update pair: https://learn.microsoft.com/en-us/dynamicsax-2012/developer/x-standards-ttsbegin-and-ttscommit
ttsBegin;
//finding the proper purchase order and its line based on user-entered values. Note that we use FORUPDATE statement to allow updates to the object later
select forUpdate purchLine
where purchLine.PurchId &&
purchLine.LineNumber == purchLineNum;
//if we were able to find the record, execute validation and business logic. if not - throw meaningful error message
if(purchLine)
{
if((purchLine.RemainPurchFinancial purchLine.invoicedInTotal()) >= purchLine.PurchQty)
{
info(strFmt("Record for Purchase order %1 with line number %2 cannot be updated.",purchOrderNum,purchLineNum));
}
else
{
purchLine.PurchQty = purchLine.RemainPurchFinancial purchLine.invoicedInTotal();
purchLine.update();
}
}
else
{
error(strFmt("Record for Purchase order %1 with line number %2 is not found.",purchOrderNum,purchLineNum));
}
ttsCommit;
}
else
{
return;
}
}
[View:/cfs-file/__key/communityserver-discussions-components-files/33/Job_5F00_community_5F00_forum_5F00_468941.xpo:320:240
Hope this helps with your learning!