In this blog of DynamicsCommunity101 we will learn Dynamics 365 FO COC for Button Click in standard form
[ExtensionOf(FormControlStr(SalesTableListPage, NotForMRP))]
final class LSSalesTableListpage_NotForMRP_Extension
{
public void clicked()
{
FormControl formButtonControl = any2Object(this) as FormControl;
FormDataSource salesTable_ds = formButtonControl.formRun().dataSource(tableStr(SalesTable));
SalesTable salesTable = salesTable_ds.cursor(),salesTableUpdate;
SalesLine SalesLineLocal;
CustParameters CustParametersLocal = CustParameters::find();
TransDate LSRequestedShipDateLocal,LSRequestedReceiptDateLocal;
boolean ret = false;
try
{
ttsbegin;
if(salesTable.LSNotForMRP == NoYes::No)
{
select forupdate salesTableUpdate
where salesTableUpdate.RecId == salesTable.RecId;
salesTableUpdate.LSNotForMRP = NoYes::Yes;
ttsbegin;
salesTableUpdate.update();
ttscommit;
while select forupdate SalesLineLocal
where SalesLineLocal.SalesId == salesTable.SalesId
{
LSRequestedShipDateLocal = SalesLineLocal.ShippingDateRequested;
LSRequestedReceiptDateLocal = SalesLineLocal.ReceiptDateRequested;
SalesLineLocal.LSRequestedShipDate = LSRequestedShipDateLocal;
SalesLineLocal.LSRequestedReceiptDate = LSRequestedReceiptDateLocal;
SalesLineLocal.ShippingDateRequested = CustParametersLocal.LSMRPDate;
SalesLineLocal.ReceiptDateRequested = CustParametersLocal.LSMRPDate;
ttsbegin;
SalesLineLocal.update();
ttscommit;
}
info("@LS_HISOL_AY:NotForMRP");
}
else
{
select forupdate salesTableUpdate
where salesTableUpdate.RecId == salesTable.RecId;
salesTableUpdate.LSNotForMRP = NoYes::No;
ttsbegin;
salesTableUpdate.update();
ttscommit;
while select forupdate SalesLineLocal
where SalesLineLocal.SalesId == salesTable.SalesId
{
LSRequestedShipDateLocal = SalesLineLocal.LSRequestedShipDate;
LSRequestedReceiptDateLocal = SalesLineLocal.LSRequestedReceiptDate;
SalesLineLocal.ShippingDateRequested = LSRequestedShipDateLocal;
SalesLineLocal.ReceiptDateRequested = LSRequestedReceiptDateLocal;
SalesLineLocal.LSRequestedShipDate = CustParametersLocal.LSMRPDate;
SalesLineLocal.LSRequestedReceiptDate = CustParametersLocal.LSMRPDate;
ttsbegin;
SalesLineLocal.update();
ttscommit;
}
info("@LS_HISOL_AY:ForMRP");
}
ttscommit;
}
catch
{
System.Exception ex = CLRInterop::getLastException();
error(ex.Message);
}
salesTable_ds.reread();
next clicked();
}
}