Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

To trigger the error on workflow submit button .

(0) ShareShare
ReportReport
Posted on by 1,457
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
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,349 Super User 2024 Season 2 on at
    To trigger the error on workflow submit button .
    Hi Dinesh,

    Apologies i just noticed that in your last reply you are using 1 if condition instead of 3 and i can understand now why you want invoiceAmount to be checked outside the loop. However, i also suggested other improvements inside the if condition. But i can see you already changed the logic somehow,  so here is a a little bit of enhancement on the code related to the while loop
                while select InvoicedNow from psaProjProposalProj
                where  psaProjProposalProj.ProjProposalId ==  projProposalJour.ProposalId
                {
                    if( psaProjProposalProj.InvoicedNow <= 0)
                    {
                        select firstonly projParameters
                            where  projParameters.DataAreaId == projProposalJour.DataAreaId;
    
                        select Reason from   reasonTableRef
                                where   reasonTableRef.RecId ==  projProposalJour.ReasonTableRef;
    
                        if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes &&  projProposalJour.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.");
                            }
                        }
    
                        if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonTableRef.Reason == '')
                        {
                            throw error("The Reason Code field is mandatory. Cannot proceed further.");
    
                        }
                      
                    }
                }


    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
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,613 Super User 2024 Season 1 on at
    To trigger the error on workflow submit button .
    From your problem statement it seems to that error should be thrown once click on submit. 
     
    If you want the error to show before the dialog opens, then as you have written before dialog opens, it works. From your last code, you need to throw the error not to show the info.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To trigger the error on workflow submit button .
    hi 
    layan , 
    thanks for reply , 
     
    actually i want to threw error before the dialog opens i have keep only one if condition as you say , if i use this statement saperately, its not getting hit , so i used it inside the previous if .  
     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;
                        }
                    }
    and i dont have to use  "if( PSAProjProposalProj.InvoicedNow <= 0)" two times.
    tat's why i keep all conditions in one if .
     
    thanks ,
    Regards,
    Dinesh
  • Layan Jwei Profile Picture
    Layan Jwei 7,349 Super User 2024 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
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 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
    Layan Jwei 7,349 Super User 2024 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
    Dineshkarlekar 1,457 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
     
  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    To trigger the error on workflow submit button .
    Bharani's suggestion sounds better. I failed to find PSAProjInvoiceProposalWorkflow class.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,613 Super User 2024 Season 1 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.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans