Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Submit button called in PSAProjInvoiceProposalSubmitToWF

(1) ShareShare
ReportReport
Posted on by 36
 
class PSAProjInvoiceProposalSubmitToWF
{
    protected void new()
    {
        return;
    }
    public static void main(Args _args)
    {
        RecID                   recID               = _args.record().RecId;
        TableId                 tableId             = _args.record().TableId;
        ProjProposalJour        projProposalJour    = _args.record();
        WorkflowWorkItemTable   workItem            = _args.caller().getActiveWorkflowWorkItem();
        WorkflowSubmitDialog    workflowSubmitDialog;
        WorkflowComment         wfComment;
        workflowTypeName        workflowTemplateName = workFlowTypeStr('PSAProjInvoiceProposal');
        // The method has not been called correctly.
        if (tableId != tablenum(ProjProposalJour) ||
            recId == 0)
        {
            throw error(strfmt("@SYS19306", funcname()));
        }
        if (projProposalJour.RecId != 0)
        {
            // The journal does support workflow approvals.
            workflowSubmitDialog = WorkflowSubmitDialog::construct(_args.caller().getActiveWorkflowConfiguration());
            workflowSubmitDialog.run();
            if (WorkflowSubmitDialog.parmIsClosedOK())
            {
                wfComment=WorkflowSubmitDialog.parmWorkflowComment();
                if (ProjProposalJour::findRecid(recID).LineProperty == ProjLinePropertyCode::Open)
                {
                    // Validates and disallow workflow submission when project is in closed stage for invoice proposal.
                    PSAProjInvoiceProposalSubmitToWF::disallowSubmitIfProjStageIsClosed(projProposalJour.ProposalId);
                    // Create a new workflow from the workflow template used on the workflow configuration associated to the journal's journal name.
                    Workflow::activateFromWorkflowType(workflowTemplateName, _args.record().RecId, wfComment, NoYes::No);
                    // Set the workflow status to Submitted.
                    PSAProjInvoiceProposalStateChangeManager::updateProjInvoiceProposalStatus(_args.record().RecId,ProjLinePropertyCode::PSASubmitted);
                }
            }
        }
        // Make the form refresh its common workflow UI controls.
        PSAProjInvoiceProposalSubmitToWF::refreshCaller(_args);
    }
    public static void refreshCaller(Args _args)
    {
        FormRun         callerForm;
        FormDataSource  projProposalJourDS;
        if (_args.caller())
        {
            if (SysDictClass::isEqualOrSuperclass(classidget(_args.caller()), classnum(FormRun)))
            {
                callerForm = _args.caller();
                projProposalJourDS = FormDataUtil::getFormDataSource(_args.record());
                if (projProposalJourDS)
                {
                    projProposalJourDS.reread(); 
                    projProposalJourDS.refresh();
                    projProposalJourDS.active();
                    callerForm.updateWorkflowControls();
                }
            }
        }
    }
    /// <summary>
    /// Validates project stage to allow creation of invoice proposal before submit to workflow. An error will be thrown if project stage is not allowed for invoice proposal creation.
    /// </summary>
    /// <param name="_proposalId">
    /// Reference to invoice proposal ID.
    /// </param>
    protected static void disallowSubmitIfProjStageIsClosed(ProjProposalId _proposalId)
    {
        ProjProposalTransUnion projProposalTransUnion;
        ProjTable projTable;
        while select ProjId, Status, Type, ProjInvoiceProjId
              from projTable
                 exists join projProposalTransUnion
                     where projProposalTransUnion.ProjId == projTable.ProjId
                         && projProposalTransUnion.ProposalId == _proposalId
        {
            if (projTable && !ProjStatusTypeRule::exist(projTable.Status, projTable.Type, ProjStatusRule::CreateInvoiceProposal))
            {
                throw error(strFmt("@Proj:ProjClosedStageSubmitToWorkflowError", projTable.ProjId, projTable.Stage()));
            }
        }
    }
}
 guide me on which instruction where the submit button action triggered.
Thanks in advance.
 
  • André Arnaud de Calavon Profile Picture
    293,112 Super User 2025 Season 1 on at
    Submit button called in PSAProjInvoiceProposalSubmitToWF
    Hi,

    Can you explain your question, please? What is it exactly where and how you need help with?
  • Martin Dráb Profile Picture
    231,893 Most Valuable Professional on at
    Submit button called in PSAProjInvoiceProposalSubmitToWF
    I'm not sure what you're looking for, but probably for this:
    // Create a new workflow from the workflow template used on the workflow configuration associated to the journal's journal name.
    Workflow::activateFromWorkflowType(workflowTemplateName, _args.record().RecId, wfComment, NoYes::No);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,112 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,893 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans