On clicked event of form button in D365 X++
Form : SalesQuotationListPage
Button : DH_AmendmentButton
DataSource : SalesQuotationTable
[FormControlEventHandler(formControlStr(SalesQuotationListPage, DH_AmendmentButton), FormControlEventType::Clicked)]
public static void DH_AmendmentButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
FormRun fromRunLoc;
FormDataSource formDataSourceLoc;
SalesQuotationTable salesQuoteTable;
DH_SalesQuote DHQuote;
fromRunLoc = sender.formRun();
formDataSourceLoc = sender.formRun().dataSource("SalesQuotationTable");
salesQuoteTable = formDataSourceLoc.cursor();
ttsbegin;
select firstonly forupdate DH_DocumentWorkflowState from DHQuote
where DHQuote.QuotationId == salesQuoteTable.QuotationId;
if (DHQuote.DH_DocumentWorkflowState == DH_DocumentWorkflowState::Completed)
{
DHQuote.DH_DocumentWorkflowState = DH_DocumentWorkflowState::NotSubmitted;
DHQuote.update();
info("Workflow status changed to draft");
}
ttscommit;
}
Button : DH_AmendmentButton
DataSource : SalesQuotationTable
[FormControlEventHandler(formControlStr(SalesQuotationListPage, DH_AmendmentButton), FormControlEventType::Clicked)]
public static void DH_AmendmentButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
FormRun fromRunLoc;
FormDataSource formDataSourceLoc;
SalesQuotationTable salesQuoteTable;
DH_SalesQuote DHQuote;
fromRunLoc = sender.formRun();
formDataSourceLoc = sender.formRun().dataSource("SalesQuotationTable");
salesQuoteTable = formDataSourceLoc.cursor();
ttsbegin;
select firstonly forupdate DH_DocumentWorkflowState from DHQuote
where DHQuote.QuotationId == salesQuoteTable.QuotationId;
if (DHQuote.DH_DocumentWorkflowState == DH_DocumentWorkflowState::Completed)
{
DHQuote.DH_DocumentWorkflowState = DH_DocumentWorkflowState::NotSubmitted;
DHQuote.update();
info("Workflow status changed to draft");
}
ttscommit;
}
Comments
Post a Comment