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

X++ create a onvalidating events in D365FO?

(0) ShareShare
ReportReport
Posted on by 1,215

HI, guys 

i wrote a events OnvalidatingWrite  when i fill the applicant form new record we want to fill the Contact information mandatory  

but, this code when i save applicant form after getting the error throw but, i before close form it is closing what to be done?

[FormDataSourceEventHandler(formDataSourceStr(HcmApplicant, HcmApplicant), FormDataSourceEventType::ValidatingWrite)]
public static void HcmApplicant_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e)
{
var datasource = sender as FormDataSource;
var args = e as FormDataSourceCancelEventArgs;
var Applicants = datasource.cursor() as HcmApplicant;
HcmApplicant applicant;
DirPerson person;
DirPersonName personName;
LogisticsElectronicAddress electronicAddress;
DirPartyTable dirPartyTable;

select firstOnly applicant
join Person
where Person.RecId== applicant.Person
&& applicant.ApplicantId == applicant.ApplicantId
join personName
where personName.Person == person.RecId
join dirPartyTable
where dirPartyTable.RecId == person.RecId
join electronicAddress
where electronicAddress.PrivateForParty == dirPartyTable.RecId;

if (!electronicAddress.Location)
{
boolean doCancel = checkFailed("Must be filled Contact details.");
args.cancel();
}
}

regards,

Riyas ahmed F

I have the same question (0)
  • Riyas ahamed F Profile Picture
    1,215 on at
    RE: X++ create a onvalidating events in D365FO?

    Thanks for your valuable answer Evaldas.

    Regards,

    Riyas ahamed F

  • Verified answer
    Evaldas Profile Picture
    1,800 on at
    RE: X++ create a onvalidating events in D365FO?

    First of all I suggest to use CoC on your form datasource or on table's method, it's much easier.

    Second, it's probably a good idea to select firstonly electronicAddress and exists join everything else.

    Third, you are using applicant.ApplicantId == applicant.ApplicantId in your where clause which is a mistake as you are not binding it to the record you are trying to validate.

  • Riyas ahamed F Profile Picture
    1,215 on at
    RE: X++ create a onvalidating events in D365FO?

    Many thanks Mohammed.

  • Verified answer
    mhdshb1 Profile Picture
    1,250 on at
    RE: X++ create a onvalidating events in D365FO?

    Hi Ahmed,

    Try this piece of code 

    I have changed the declaration of the args variable to be ValidateEventArgs

    And you need to use the parmValidResult method and pass the result parameter

        [FormDataSourceEventHandler(formDataSourceStr(HcmApplicant, HcmApplicant), FormDataSourceEventType::ValidatingWrite)]
        public static void HcmApplicant_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e)
        {
            var datasource = sender as FormDataSource;
            ValidateEventArgs args = e as ValidateEventArgs;
            boolean result = args.parmValidateResult(); 
            var Applicants = datasource.cursor() as HcmApplicant;
            HcmApplicant applicant;
            DirPerson person;
            DirPersonName personName;
            LogisticsElectronicAddress electronicAddress;
            DirPartyTable dirPartyTable;
    
                select firstOnly applicant
                join Person
                where Person.RecId== applicant.Person
                && applicant.ApplicantId == applicant.ApplicantId
                join personName
                where personName.Person == person.RecId
                join dirPartyTable
                where dirPartyTable.RecId == person.RecId
                join electronicAddress
                where electronicAddress.PrivateForParty == dirPartyTable.RecId;
    
                if (!electronicAddress.Location)
                {
                    result  = checkFailed("Must be filled Contact details.");
                   
                }
            args.parmValidateResult(result);
        }

    Regards,

    Mohammad

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 825 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 601

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans