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

Validating in form extension without datasources

(0) ShareShare
ReportReport
Posted on by

Hello , I need to validate a create form without datasources.

Validating is based on 2 FormControls from EcoResProductCreate form.

1.  formControlStr(EcoResProductCreate, Types_ProductType)

2. formControlStr(EcoResProductCreate, SalesPrice)

For validating I take event handler in extension class but I dont know how to extract and interact with FormControls without datasources.

    [FormControlEventHandler(formControlStr(EcoResProductCreate, Types_ProductType), FormControlEventType::Validating)]
    public static void Types_ProductType_OnValidating(FormControl sender, FormControlEventArgs e)
    {
        FormControl fc = element.design().controlName(Types_ProductType);
        var args = e as FormControlEventArgs;
        boolean ret;

        ret = checkFailed('%1',fc.text());
        args.cancel(ret );
    }

    [FormControlEventHandler(formControlStr(EcoResProductCreate, SalesPrice), FormControlEventType::Validating)]
    public static void SalesPrice_OnValidating(FormControl sender, FormControlEventArgs e)
    {


    }

(I was trying some advice from web)

? How can I get Value from Form Controls and return checkFailed properly ?

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Validating in form extension without datasources

    Try this:

            FormControlCancelEventArgs eventArgs = e as FormControlCancelEventArgs;
            info("not valid!");
            eventArgs.cancel(true);

  • Community Member Profile Picture
    on at
    RE: Validating in form extension without datasources
    [quote

    Could you please share your full event handler code? 

    [/quote

     [FormControlEventHandler(formControlStr(EcoResProductCreate, Types_ProductType), FormControlEventType::Validating)]
        public static void Types_ProductType_OnValidating(FormControl sender, FormControlEventArgs e)
        {
            
            FormComboBoxControl             productTypeControl = sender as FormComboBoxControl;
            EcoResProductType               productType = productTypeControl.selection();
            var                             args = e as ValidateEventArgs;
            FormRun                         formRun = sender.formRun();
    
            FormRealControl                 salesPriceControl = formRun.control(formRun.controlId(
                                                                    FormControlStr(EcoResProductCreate, SalesPrice)));
            str                             salesPriceValue = salesPriceControl.valueStr();
            boolean                         ret = args.parmValidateResult();
    
            if(productType == EcoResProductType::Service || salesPriceValue.toReal() == 0 )
            {
                ret = true && ret;
            }
            else
            {
                ret = checkFailed('@els:els97') && ret;
            }
            args.parmValidateResult(ret);    
            info(strFmt("%1", productType));
        }

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: Validating in form extension without datasources

    I fixed my code 1-2 minutes after posting (I forgot to fix it while I was copy-pasting your code). I think you got it without me correcting it.

    But it seems like the problem is using values. You can get the value of the other control as you did first control, just be careful with its type.

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Validating in form extension without datasources

    Could you please share your full event handler code? 

  • Community Member Profile Picture
    on at
    RE: Validating in form extension without datasources

    But how can I validate it now ?

    pastedimage1641399219513v1.png

    I was using the code from comments above.

     var                             args = e as ValidateEventArgs;
     args.parmValidateResult(ret);

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Validating in form extension without datasources

    d365-solutions.blogspot.com/.../access-form-controls-in-form-event.html

  • Community Member Profile Picture
    on at
    RE: Validating in form extension without datasources

    But how can I take another FormControl from same form. Because for my validations rules I need both of values of FormControls to do validation. If I take this from sender how can I take another formControlStr(EcoResProductCreate, SalesPrice) form control value.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Validating in form extension without datasources

    You have the form control in the "sender" parameter of the event handler method.

    You need to cast it to a correct type, something like this:

        [FormControlEventHandler(formControlStr(EcoResProductCreate, Types_ProductType), FormControlEventType::Validating)]
        public static void Types_ProductType_OnValidating(FormControl sender, FormControlEventArgs e)
        {
            FormComboBoxControl productTypeControl = sender as FormComboBoxControl;
            EcoResProductType productType = productTypeControl.selection();
            
            info(strFmt("%1", productType));
        }

  • Community Member Profile Picture
    on at
    RE: Validating in form extension without datasources

    Bingo. I dont know how I can get the value from form control bcs I was using before it only code like:

    datasource.object(fieldNum(tableName, fieldName)).getValue();

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: Validating in form extension without datasources

    Reading your first post again, I think you actually don't even have any problems in the validation itself (set true/false based on a condition). Am I correct? But you don't know how to read the value of the form control?

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 2,370

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 675 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans