Skip to main content

Notifications

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

To trigger the error on form when the fields are empty

Posted on by 1,457
hi , 
every one ,
 I have added the field on parameters form , so when i make this fields toggle to yes , there should be error thrown on 
on invoice proposals form on the click of post button , that the reason code and method of payment should not be empty .how can i get this done can anyone guide me on this . 
thanks ,
Regards,
Dinesh.
 
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,328 Super User 2024 Season 2 on at
    To trigger the error on form when the fields are empty
    Hi Dinesh,
     
    I can see that you started selecting projParameters as i first advised and that you stopped marking the fields as mandatory but rather checking the parameter value and if the field is empty.
    So i'm glad it works now for you -- please don't forget to verify the answer
     
    Now for your new condition, it seems you want to apply this condition based on each line that has the amount <0..if that's your intention then you can do that.. it depends on your business need ( i can't tell which tables or conditions you should use)

    My comment is why do you join to projProposdlJourds again in while select if you already have it defined when you used formDataSource.cursor()
     
    Wouldn't the following work?
    while select InvoicedNow from psaProjProposalProj
    where psaProjProposalProj.ProjProposalId = projProposalJourds.ProposalId && psaProjProposalProj.InvoicedAmount <0
     
    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
    Waed Ayyad Profile Picture
    Waed Ayyad 6,225 Super User 2024 Season 2 on at
    To trigger the error on form when the fields are empty
    ​​​​​​​
    I see my first reply helped you, can you verify it, in order to help other who will face the same issue in the future.

    I have a question for you why you use While select? You want to check all records?

    I did some changes on your code, check it please:

    [ExtensionOf(formControlstr(ProjInvoiceProposalDetail,ProjFormLetter_Invoice))]
    final class DTInvoicepropCreditnt_Extension
    {
        public void clicked()
        {
            FormButtonControl     formButtonControl = any2Object(this) as FormButtonControl;
            FormDataSource        formDatasource     = formButtonControl.formRun().dataSource(tableStr(ProjProposalJour));
            ProjProposalJour      projProposalJourds = formDatasource.cursor();
            FormControl           formControl =  formButtonControl;
            FormRun               formRun = formControl.formRun();
            FormStringControl     ReasonCode  = formRun.design().controlName(formControlStr(ProjInvoiceProposalDetail, Reason_M_editReasonCode )) as   FormStringControl ;
            PSAProjProposalProj    pSAProjProposalProj;
            ProjParameters         projParameters   =  ProjParameters::find();   
     
     
           while select InvoicedNow from PSAProjProposalProj
                join projProposalJourds
              where  PSAProjProposalProj.ProjProposalId ==projProposalJourds.ProposalId
              &&     PSAProjProposalProj.InvoicedNow <= 0
            {
               //formDatasource.object(methodStr(ProjProposalJour,editReasonCode)).mandatory(projParameters.DTReasonCodeMandatory);
               //formDatasource.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(projParameters.DTOriginalInvoiceMandatory);
               if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && projProposalJourds.PaymMode == '')
                {
                    throw error("The  method of  payment  field is mandatory. Cannot proceed further.");
                }
                if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonCode == null)
                {
                    throw error("The Reason Code field is mandatory. Cannot proceed further.");
                }
            }
            next clicked();
        }
    }

    Thanks,
    Waed Ayyad
    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
    ​​​​​​​
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To trigger the error on form when the fields are empty
    hi , everyone , i have made some changes in my code , plz suggest me if i need to make any changes ,
    as i have added the condition that if 
     while select InvoicedNow from PSAProjProposalProj
                join projProposalJourds
              where  PSAProjProposalProj.ProjProposalId ==projProposalJourds.ProposalId
            {
                if( PSAProjProposalProj.InvoicedNow <= 0)
    {
    }
             
    }
    so if the reocrd in table is having the nagative value then only this condition works .
    below is my code .
    [ExtensionOf(formControlstr(ProjInvoiceProposalDetail,ProjFormLetter_Invoice))]
    final class DTInvoicepropCreditnt_Extension
    {
        public void clicked()
        {
            FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
          
            FormDataSource     formDatasource     = formButtonControl.formRun().dataSource(tableStr(ProjProposalJour));
            ProjProposalJour   projProposalJourds = formDatasource.cursor();
            FormControl        formControl =  formButtonControl;
            FormRun            formRun = formControl.formRun();
            FormStringControl     ReasonCode  = formRun.design().controlName(formControlStr(ProjInvoiceProposalDetail, Reason_M_editReasonCode )) as   FormStringControl ;
            PSAProjProposalProj    pSAProjProposalProj;
            ProjParameters     projParameters;    
           
    
            select firstonly projParameters;
    
           while select InvoicedNow from PSAProjProposalProj
                join projProposalJourds
              where  PSAProjProposalProj.ProjProposalId ==projProposalJourds.ProposalId
            {
                if( PSAProjProposalProj.InvoicedNow <= 0)
                {
                    //formDatasource.object(methodStr(ProjProposalJour,editReasonCode)).mandatory(projParameters.DTReasonCodeMandatory);
                    //formDatasource.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(projParameters.DTOriginalInvoiceMandatory);
    
                    if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && projProposalJourds.PaymMode == '')
                    {
                        throw error("The  method of  payment  field is mandatory. Cannot proceed further.");
                    }
    
                    if(projParameters.DTReasonCodeMandatory == NoYes::Yes && ReasonCode == null)
                    {
                        throw error("The Reason Code field is mandatory. Cannot proceed further.");
                    }
                }
            }
            next clicked();
    
        }
    
    }
    thanks 
    regards , 
    dinesh
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To trigger the error on form when the fields are empty
    hi , 
    thanks for reply guys , i have made changes in my code , 
    as reason code is the field which data coming from the method i am not getting how to add do the same for reason code , below is my code  plz guide me on this . 
    controlName(formControlStr(ProjInvoiceProposalDetail, Reason_M_editReasonCode ))
    reason code is not field on table its data come from method 
     i have made like this 
     
    [ExtensionOf(formControlstr(ProjInvoiceProposalDetail,ProjFormLetter_Invoice))]
    final class DTInvoicepropCreditnt_Extension
    {
        public void clicked()
        {
            FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
          
            FormDataSource     formDatasource     = formButtonControl.formRun().dataSource(tableStr(ProjProposalJour));
            ProjProposalJour   projProposalJourds = formDatasource.cursor();
            ProjParameters     projParameters;    
           
    
            select firstonly projParameters;
          
            formDatasource.object(methodStr(ProjProposalJour,editReasonCode)).mandatory(projParameters.DTReasonCodeMandatory);
            formDatasource.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(projParameters.DTOriginalInvoiceMandatory);
    
            if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes && projProposalJourds.PaymMode == '')
            {
                throw error("The  method of  payment  field is mandatory. Cannot proceed further.");
            }
    
            if(projParameters.DTReasonCodeMandatory == NoYes::Yes && projProposalJourds.ReasonCode == '')
            {
                throw error("The Reason Code field is mandatory. Cannot proceed further.");
            }
    
            next clicked();
    
        }
    
    }
    plz suggest me what changes i need to do for this . 
     
    thanks ,
    Regards ,
    Dinesh.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,605 Super User 2024 Season 1 on at
    To trigger the error on form when the fields are empty
    From your code, 
     
    1) You have defined the parameter buffer but not yet initialised a value for the buffer. So you need to call find method or write a select statement for the parameter table.
    2) In the if condition where you are checking, it is not required to make those particular fields as mandatory when clicking post. Your code should be in such a way that on clicked of the post button, check the fields and if empty, and parameter is yes then throw error which will stop further execution.
     
    So add a find for the parameter table and remove the mandatory related code and only check if value is empty if parameter is enabled and throw error if empty.
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,225 Super User 2024 Season 2 on at
    To trigger the error on form when the fields are empty
     
    What is the error that you got?

    I see three errors on your code:
     
    1- You don't select projParameters buffer.
    2- You called the table buffer to set the formdatasource field mandatory which is wrong.
    3- You use the same parameter field to mandatory of Method of payment and ReasonCode 
     
    Try this code and tell me the result:
     Note I named the fields based on what you mentioned but you should use  the correct names.

    [ExtensionOf(formControlstr(ProjInvoiceProposalDetail,ProjFormLetter_Invoice))]
    final class DTInvoicepropCreditnt_Extension
    {
        public void clicked()
        {
            FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
          
            FormDataSource     formDatasource     = formButtonControl.formRun().dataSource(tableStr(ProjProposalJour));
            ProjProposalJour   projProposalJourds = formDatasource.cursor();
            ProjParameters     projParameters     = ProjParameters::find();
            //purchTable.reread();
          
            formDatasource.object(fieldNum(ProjProposalJour, ReasonCode)).mandatory(projParameters.DTOriginalInvoiceMandatoryReasonCode);
            formDatasource.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(projParameters.DTOriginalInvoiceMandatory);

            if(projParameters.DTOriginalInvoiceMandatory && projProposalJourds.PaymentMethod == '')
            {
                throw error("The  method of  payment  field is mandatory. Cannot proceed further.");
            }

            if(projParameters.DTOriginalInvoiceMandatoryReasonCode && projProposalJourds.ReasonCode == '')
            {
                throw error("The Reason Code field is mandatory. Cannot proceed further.");
            }

            next clicked();
        }
    }
    Thanks,
    Waed Ayyad
    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
    Layan Jwei Profile Picture
    Layan Jwei 7,328 Super User 2024 Season 2 on at
    To trigger the error on form when the fields are empty
    Hi Dinesh,
     
    What is the error you are getting?
     
    Looking at it quickly, i can see a major issue, which is you didn't select the projParameter and you are using it directly, so that will generate an error.
     
    You need to say sth like this:
    ProjParameters projParameters= ProjParameters::find();
     
    Also you said you want to check if they are empty when the parameter is yes, but i can see you are not doing that, you are rather making them mandatory..what is the exact requirement?


    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. You can do this by ticking the box "Does this answer your question"
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    To trigger the error on form when the fields are empty
    hi , 
    thanks for reply ,
     here is my code, but i am getting error 
     
    [ExtensionOf(formControlstr(ProjInvoiceProposalDetail,ProjFormLetter_Invoice))]
    final class DTInvoicepropCreditnt_Extension
    {
        public void clicked()
        {
            FormButtonControl formButtonControl = any2Object(this) as FormButtonControl;
          
            FormDataSource     formDatasource = formButtonControl.formRun().dataSource(tableStr(ProjProposalJour));
            ProjProposalJour   projProposalJourds = formDatasource.cursor();
            ProjParameters     projParameters;   
            //purchTable.reread();
          
    
            if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes)
            {
                projProposalJourds.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(true);
                throw error("The  method of  payment  field is mandatory. Cannot proceed further.");
            }
    
            if(projParameters.DTOriginalInvoiceMandatory == NoYes::Yes)
            {
                projProposalJourds.object(fieldNum(ProjProposalJour, PaymMode)).mandatory(true);
                throw error("The Reason Code field is mandatory. Cannot proceed further.");
            }
    
            next clicked();
        }
    }
     
  • Layan Jwei Profile Picture
    Layan Jwei 7,328 Super User 2024 Season 2 on at
    To trigger the error on form when the fields are empty
    Hi Dinesh,
     
    So what you want is, if the reason code parameter is true, and in the from it's empty then throw an error when postong OR if original invoice parameter is true and payment method is empty then also throw an error?
     
    Which means you need sth like this on maybe the post clicked method (ignore the syntax just showing you the idea as I'm on my mobile)
     
    If(parameterReason == noyes::yes && this.Reason == '')
    {
        Throw error('error');
    }
    Same thing for the other field.
     
    So can you show us your code in order to know what u did wrong?
     
    Thanks,
    Layan Jweihan

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans