web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

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

To trigger the error on workflow submit button .

(0) ShareShare
ReportReport
Posted on by 1,836
HI ,
i have created the chain of command , on projproposaljour table where the  when i click on the work flow submit button and the parameters on the projparmeters are set to yes then on click of submit button i should get the error triggred i am having three conditions in error's .but the method is boolean on the opening of projproposal  form i am getting the error triggered , but it should be triggered on click of submit button . 
 
below is my code for coc , plz anyone one help me out on this .
 
 
thanks,
Regards,
Dinesh
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    To trigger the error on workflow submit button .
    [ExtensionOf(tableStr(projproposaljour))]
    final class DTProjInvoiceJourWorkFlowSubmit_Extension
    {
        public boolean canSubmitToWorkflow(str _workflowType)
        {
            PSAProjProposalProj          pSAProjProposalProj;
            ReasonTableRef               reasonTableRef;
            ProjParameters               projParameters;
    
            next  canSubmitToWorkflow( _workflowType);
            boolean ret = false;
    
            while select InvoicedNow from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId == this.ProposalId
            {
                select firstonly projParameters
                            where  projParameters.DataAreaId == this.DataAreaId;
    
                if( PSAProjProposalProj.InvoicedNow <= 0)
                {
                         
                    if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && this.DTOriginalTaxInvoiceNo == ''
                                && projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                    {
                        throw error("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                    }
                }
    
                if( PSAProjProposalProj.InvoicedNow <= 0)
                {
                         
                    if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && this.DTOriginalTaxInvoiceNo == '')
                    {
                        throw error("The Original Invoice field is mandatory. Cannot proceed further.");
                    }
                }
    
                if( PSAProjProposalProj.InvoicedNow <= 0)
                {
                    select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId == this.ReasonTableRef;
    
                    if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                    {
                        throw error("The Reason Code field is mandatory. Cannot proceed further.");
                    }
                }
            }
            return ret;
        }
    
    }
    
    this is my code , plz guide me ,what i am doing wrong in this ,
     
    thanks,
    Regards,
    Dinesh.
  • Suggested answer
    Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 on at
    To trigger the error on workflow submit button .
    Hi Dinesh,

    The method name is called "canSubmitToWorkflow", which means it will be called before you actually submit. If you want the error to appear after clicking submit, then did you debug and see what method gets called after you click submit to know what is the suitable method? there should be a submit method.
    ​​​​​​​
    btw in general, you can simplify your code to this:
        [ExtensionOf(tableStr(projproposaljour))]
        final class DTProjInvoiceJourWorkFlowSubmit_Extension
        {
            public boolean canSubmitToWorkflow(str _workflowType)
            {
                PSAProjProposalProj          pSAProjProposalProj;
                ReasonTableRef               reasonTableRef;
                ProjParameters               projParameters;
    
                next  canSubmitToWorkflow( _workflowType);
                boolean ret = false;
    
                while select InvoicedNow from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId == this.ProposalId
                    && PSAProjProposalProj.InvoicedNow <= 0
                {
                    select firstonly projParameters
                            where  projParameters.DataAreaId == this.DataAreaId;
    
                    if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes)
                    {
                        if(this.DTOriginalTaxInvoiceNo == '')
                        {
                            if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                            {
                                throw error("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                            }
                            else
                            {
                                throw error("The Original Invoice field is mandatory. Cannot proceed further.");
                            }
                        }
                    }
    
                    select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId == this.ReasonTableRef;
    
                    if(projParameters.DTReasonCodeMandatory == NoYes::Yes && reasonTableRef.Reason == '')
                    {
                        throw error("The Reason Code field is mandatory. Cannot proceed further.");
                    }
                }
                return ret;
            }
    
        }
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Suggested answer
    Martin Dráb Profile Picture
    236,570 Most Valuable Professional on at
    To trigger the error on workflow submit button .
    As you confirmed, your code is at a completely wrong place.
     
    I think you want the class that is called on submitting to workflow, which is PSAProjInvoiceProposalSubmitToWF. If you find it difficult to extend, you can create your own class, extend PSAProjInvoiceProposalSubmitToWorkflow menu item and use your class there instead of the standard one.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    To trigger the error on workflow submit button .
    In this class, PSAProjInvoiceProposalWorkflow check this method canSubmit(). This is used for throwing validation errors.
     
    Also you can try write COC on class PSAProjInvoiceProposalSubmitToWF main() method. This I haven't tried but works.
     
    These both will serve the purpose.
  • Martin Dráb Profile Picture
    236,570 Most Valuable Professional on at
    To trigger the error on workflow submit button .
    Bharani's suggestion sounds better. I failed to find PSAProjInvoiceProposalWorkflow class.
  • Dineshkarlekar Profile Picture
    1,836 on at
    To trigger the error on workflow submit button .
    hi
    every one thanks for reply , 
     i have made the COC of PSAProjInvoiceProposalSubmitToWF main() method , need to throw the error before the opening the dialog , so i add my condition before the dialog run 
    , below is my code , plz suggest me what changes i have to make.
     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');
            PSAProjProposalProj     pSAProjProposalProj;
            ReasonTableRef          reasonTableRef;
            ProjParameters          projParameters;
    
           
            // The method has not been called correctly.
            if (tableId != tablenum(ProjProposalJour) ||
                recId == 0)
            {
                throw error(strfmt("@SYS19306", funcname()));
            }
    
            if (projProposalJour.RecId != 0)
            {
                while select InvoicedNow from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId ==  projProposalJour.ProposalId
                {
                    select firstonly projParameters
                            where  projParameters.DataAreaId == projProposalJour.DataAreaId;
    
                    if( PSAProjProposalProj.InvoicedNow <= 0)
                    {
    
                        if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == ''
                                && projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                            info("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                    }
    
                    if( PSAProjProposalProj.InvoicedNow <= 0)
                    {
    
                        if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == '')
                        {
                            info("The Original Invoice field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                    }
    
                    if( PSAProjProposalProj.InvoicedNow <= 0)
                    {
                        select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId ==  projProposalJour.ReasonTableRef;
    
                        if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                           Info("The Reason Code field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                    }
                }
                else
                {
                // The journal does support workflow approvals.
                workflowSubmitDialog = WorkflowSubmitDialog::construct(_args.caller().getActiveWorkflowConfiguration());
                workflowSubmitDialog.run();
                }
    thanks ,
    regards,
    Dinesh
     
  • Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 on at
    To trigger the error on workflow submit button .
    Hi Dinesh,

    1. what is the result of your code? when the error is appearing now? i thought you want the error after the dialog
    2. In my first comment, i sent improvement to your code but i can still see your are using your old code, please check it out. why looping for everything if you are only interested with invoice amount <0 ? and why keep repeating the if condition three times?


    Thanks,
    Layan Jweihan
  • Dineshkarlekar Profile Picture
    1,836 on at
    To trigger the error on workflow submit button .
    hi 
    everyone ,
    thanks for reply , 
    i have made changes in my code , and its working fine , below is my code , plz suggest if i have to change any thing .
     
     
    [ExtensionOf(classStr(PSAProjInvoiceProposalSubmitToWF))]
    final class DTPSAProjInvoiceProposalSubmitToWF_Extension
    {
       //  Description    : test if the invoice proposal can be submitted to workflow
       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');
            PSAProjProposalProj     pSAProjProposalProj;
            ReasonTableRef          reasonTableRef;
            ProjParameters          projParameters;
    
           
            // The method has not been called correctly.
            if (tableId != tablenum(ProjProposalJour) ||
                recId == 0)
            {
                throw error(strfmt("@SYS19306", funcname()));
            }
    
            if (projProposalJour.RecId != 0)
            {
                while select InvoicedNow from pSAProjProposalProj
                where  pSAProjProposalProj.ProjProposalId ==  projProposalJour.ProposalId
                {
                    select firstonly projParameters
                            where  projParameters.DataAreaId == projProposalJour.DataAreaId;
    
                    if( PSAProjProposalProj.InvoicedNow <= 0)
                    {
                        select Reason,RecId from   reasonTableRef
                                where   reasonTableRef.RecId ==  projProposalJour.ReasonTableRef;
    
                        if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == ''
                                && projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                            throw error("The Original Invoice field & Reason Code field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                        else if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.DTOriginalTaxInvoiceNo == '')
                        {
                            throw error("The Original Invoice field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                        else if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                            throw error("The Reason Code field is mandatory. Cannot proceed further.");
                            //ret = ret && false;
                        }
                      
                    }
                }
    
            }
    
            // Make the form refresh its common workflow UI controls.
            PSAProjInvoiceProposalSubmitToWF::refreshCaller(_args);
            next Main(_args);
        }
    
    }
     thanks,
    Regards,
    Dinesh
  • Layan Jwei Profile Picture
    8,049 Super User 2025 Season 2 on at
    To trigger the error on workflow submit button .
    Hi Dinesh,

    I will say it again, I suggested how to improve your code to enhance performance and readability of the code, but you are still using your old code

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,771

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 806 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 542 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans