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)

Increment A string value by 1

(0) ShareShare
ReportReport
Posted on by 353

Hi -

  I have a bit of a complex requirement (at least I believe so) . We have a string field as ACH#. The format of the string value is always the same like this "ACH-18-041, ACH-18-042, ACH-18-043".  My job is to read this string value for example  "ACH-18-043" and increment the last digit on the number "043" to "044". How can I achieve this with X++ code. ? Any help will be much appreciated.

I have to use x++ cant work with number sequence FW.

Regards

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    Firstly,you can retrieve the last 3 digits by substring function

    msdn.microsoft.com/.../aa677836.aspx

    After that converts this string to integer with str2int function

    msdn.microsoft.com/.../aa845181.aspx

    Also you can check this thread to increment value

    community.dynamics.com/.../146332

  • Verified answer
    Muhammad_Ali Profile Picture
    353 on at

    Hi -

     I did manage to solve this by the solution below.  I do agree that substr() can also be used to work with this requirement.

      ACH = this.MTRA_getACHNumber(_projgrant);
       buffer = new TextBuffer();
       buffer.setText(ACH);

        if (ACH like "ACH*")
        {
            while (buffer.nextToken(0, '-'))
            {
                cnt++;
                if(cnt == 1)
                {
                    ACHstr =   buffer.token();
                }
                else if(cnt == 2)
                {
                    ACHYear =  buffer.token();
                    yearCode = substr(strFmt('%1', year(systemDateGet())), 3, 2);
                    if(ACHYear == yearCode)
                    {
                        ACHYear =  buffer.token();
                    }
                    else
                    {
                        if (ACHYear < yearCode)
                        {
                            ACHYear = yearCode;
                        }
                    }
                }
                else if(cnt == 3)
                {
                    ACHcode =  buffer.token();
                    if (ACHcode like "0*")
                    {
                        ACHcode = '0' ;
                    }
                    i = str2int(buffer.token());
                    i = i + 1 ;
                }
            }
               return ACHstr + '-' + ACHYear + '-' + ACHcode + int2str(i);
        }
        else
        {
              return this.MTRA_getACHNumber(_projGrant);
        }

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