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 :
Microsoft Dynamics AX (Archived)

Form Field : Integer type field, need to show zero but keep missing.

(0) ShareShare
ReportReport
Posted on by

Hey expert,


I have this integer fields.

g0g09090.png

Every time, i add 0050 and 0080, it keeps showing 50 and 80, i know it's because it's integer data type. But i need this to show zero in front of the number inputted. I can't change it to string. Any idea how to do it?

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    one most communly used way is to use EditDisplay method

  • Suggested answer
    Hariharans87 Profile Picture
    3 on at

    If It is only for display purpose then, you can use display method else you can use edit method.

    For display method e.g.

    display str FormattedTestNo()

    {

       return strRFix(int2str(Form_DS.TestNo), 4, '0');

    }

    Result: if the value is 50, you will get 0050

  • Hariharans87 Profile Picture
    3 on at

    Sorry, I did a mistake in the example part.

    display str FormattedTestNo(Hari_Test Form_DS)

    {

      return strRFix(int2str(Form_DS.TestNo), 4, '0');

    }

    We should pass the form datasource if we use display method in the form.

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at

    "Every time, i add 0050 and 0080" depicts that he/she want to use it for data entry, so display method will be worthless

  • Dauvis Profile Picture
    170 on at

    An edit method is the probably the best way to do this.  The drawback on that will be that the field will not be available for filtering.

  • Hariharans87 Profile Picture
    3 on at

    Yes. You can't filter and sort the edit and display method's data. If you want filter method, you should go for string field.

  • Community Member Profile Picture
    on at

    Hi Hari, thanks for your code example.

    From your's example here's my code :

    display str FormattedNoFrom(DDSetupDDDetail _DDSetupDDDetail)

    {

     return strRFix(int2str(_DDSetupDDDetail.SetupTaxNoFrom), 4, '0');

    }

    I create this method on form/datasource/tablename's method.

    Now i should assign it to dataMethod of control property right? But when i do so, the field suddenly cannot be edited and always showing this number 3145776

  • Community Member Profile Picture
    on at

    Hi Sohaib, can you give me example code like Hari did earlier, about edit method?

    I'm planning to create it in form/Datasource's method. Thanks.

    I need example code of editmethod.

  • Hariharans87 Profile Picture
    3 on at

    Please use the below code for edit method and make sure your field maximum length is 4. If it is not 4 then, please mention the maximum length number strRFix function.

    edit str editFormattedNoFrom(boolean set, DDSetupDDDetail _DDSetupDDDetail, str enteredNo)
    {
        int taxNo;
        if(Set)
        {
            taxNo = str2int(enteredNo);
            _DDSetupDDDetail.SetupTaxNoFrom = taxNo;
        }
        else
        {
            taxNo = _DDSetupDDDetail.SetupTaxNoFrom;
        }
    
        return strRFix(int2str(taxNo), 4, '0');
    }


  • Community Member Profile Picture
    on at

    Hi, i keep getting error on this, operand not compatible

    edit SetupTaxNoFrom formattedNoFrom(                 ->my EDT with type int not string

           boolean _set,

           SetupVATDetail _SetupVATDetail,                      ->my datasourcename in form

           SetupTaxNoFrom _SetupTaxNoFrom)                ->my EDT again right

    {

       return strRFix(int2str(_SetupVATDetail.SetupTaxNoFrom), 4, '0');      ->return string??

    }

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans