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

Notifications

Announcements

No record found.

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)
  • Verified answer
    mhdshb1 Profile Picture
    1,250 on at

    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

  • Riyas ahamed F Profile Picture
    1,215 on at

    Many thanks Mohammed.

  • Verified answer
    Evaldas Profile Picture
    1,800 on at

    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

    Thanks for your valuable answer Evaldas.

    Regards,

    Riyas ahamed F

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans