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

In X++ onValidatingField

(0) ShareShare
ReportReport
Posted on by 1,215

Hi guys,

/// 
    ///
    /// 
    /// 
    /// 
    [DataEventHandler(tableStr(HcmJob), DataEventType::ValidatingField)]
    public static void HcmJob_onValidatingField(Common sender, DataEventArgs e)
    {
        HcmJob  thisRecord = sender as HcmJob ;
        ValidateFieldEventArgs event = e as ValidateFieldEventArgs;
        FieldId fieldId = event.parmFieldId();
        boolean ok = event.parmValidateResult();
        switch(fieldId )
        {
       
            case fieldNum(HcmJob, PhoneNumber):

                if(ok && strLen(int2Str(thisRecord.PhoneNumber)) !=10)
                {
                    ok = checkFailed('Phone number should be in 10 digit only!');
                }

                break;
            default:
       }

        event.parmValidateResult(Ok);

    }

sorry for the stupid question. 

My Requirement in phone number 10 digit only so that i wrote OnvalidatingField Events in Hcmjob 

in my phone number integer filed and i don't want to add String.  

1. if i gives 10 digit number i am getting error

Phone.PNG

so i cannot give it to 10 digit number how did i mistake and what should i do?

Thanks.

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    Hi Riyas,

    What is your field type? int? Have you tried Int64.

    Besides that, you can use string control,then try to use regular expression.

    67241.PNG

  • Maverick Profile Picture
    182 on at

    Hi Riyaz,

    Can you try int642str instead of int2str

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Phone numbers are not integers, they should be stored as strings. Remember that phone number can:

    - start with zero

    - have special characters such as +

    - often people prefer to put spaces in between the number to make it more easily readable

    And, as you noticed with your error message, integer data type can't store numbers that are 10 numbers long. Int64 could do that but as mentioned above, it's still not the data type that you should use.

    So, integer is not the correct data type to use. And if you look at Phone data type in AOT, you notice it's a string. Phone numbers are stored in LogisticsElectronicAddress.Locator which is also a string.

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your replay blue wang,

    i tried in Int64 but same error came what should i do.

  • Verified answer
    Blue Wang Profile Picture
    on at

    Hi Riyas,

    So, as mentioned,  you have to use string ,write code to verify the value.

    community.dynamics.com/.../validation-for-numeric-values-in-ax

  • Riyas ahamed F Profile Picture
    1,215 on at

    Thanks for your valuable answer Nikolaos Mäenpää.

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 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans