Recall workflow through Code after completion of Workflow

Recall workflow through Code after completion of Workflow

Code: 

Public class DSSH_SalesOrderWFRecall
{

    


    /// <summary>
    /// Class entry point. The system will call this method when a designated menu
    /// is selected or when execution starts and this class is set as the startup class.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        salesTable salesTable = _args.record() as SalesTable;
        FormRun formRun = _args.caller();
        FormDataSource fds = formRun.dataSource(formDataSourceStr(SalesTable, SalesTable));

        DSSH_SalesOrderWFRecall SalesOrderWFRecall = new DSSH_SalesOrderWFRecall();
        SalesOrderWFRecall.run(salesTable);

        fds.refresh();
        fds.reread();
        fds.research(true);
        
    }

    public void run(SalesTable  salesTable)
    {
        if(this.isValidToRecall(salesTable))
        {
            this.updateWorkflowStatus(salesTable);
        }
        
    }

    private boolean isValidToRecall(SalesTable  salesTable)
    {
        boolean ret = true;;


        if(salesTable.DSSH_WorkFlowStatus == DSSH_WorkFlowStatus::NotSubmitted)
        {
            
            throw error('Alert!  Request is not valid');
        }

        return ret;
    }

    private void updateWorkflowStatus(SalesTable  salesTable)
    {

        ttsbegin;
        salesTable.selectForUpdate(true);
        salesTable.reread();
        salesTable.DSSH_WorkFlowStatus = DSSH_WorkFlowStatus::NotSubmitted;
        salesTable.update();
        ttscommit;



    }

}

Comments

Popular posts from this blog

D365FO – AX – X++ –Refresh, Reread, Research, and ExecuteQuery

Create Inventory Journal through Code in D365FO X++

SalesLine Reservation in D365fo x++