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

Standard way to reverse INCSTR Function.

(0) ShareShare
ReportReport
Posted on by 2,976

Hello,

Is there a way to decrease the String value, as INCSTR do increase the String value

E.G.

String := C0001;

INCSTR(String)==> C0001 -> C0002 ;

You can also suggest your Custom Function. But i am looking for the efficient way to handle this function.

 

Thanks. 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    keoma Profile Picture
    32,729 on at
    RE: Standard way to reverse INCSTR Function.

    the links i provided show typical looooong nav style functions.

    using .net classes i developed a much smaller, cooler function:

    // loc. vars

    // DocNo : Code-20

    ---------------------------------

    OnRun()

    DocNo := DecStr('ABC00010'); // typical document no.

    MESSAGE(DocNo);

    ---------------------------------

    // loc. vars

    Prefix Text

    NoString Text

    Number Integer

    Regex DotNet System.Text.RegularExpressions.Regex.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    DotNetInt DotNet System.Int32.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    PadLength Integer

    ---------------------------------

    DecStr(DocNo : Code[20]) : Code[20]

    Prefix := Regex.Replace(DocNo,'\d+','');

    NoString := Regex.Match(DocNo,'\d+').Value;

    Number := DotNetInt.Parse(NoString); // instead of using Evaluate

    IF Number > 0 THEN BEGIN

     Number := Number - 1;

     PadLength := STRLEN(DocNo) - STRLEN(Prefix) - STRLEN(FORMAT(Number));

     EXIT(Prefix + PADSTR('',PadLength,'0') + FORMAT(Number));

    END;

    ERROR('Resulting number would be negative.');

    ---------------------------------

    Results in: ABC00009

    the resulting number has the same length. 

  • Suggested answer
    Ashwini Tripathi Profile Picture
    4,624 on at
    RE: Standard way to reverse INCSTR Function.

    Write a function to extract the numeric part and decrease the number, then padding 0's add that number to the str.

  • keoma Profile Picture
    32,729 on at
    RE: Standard way to reverse INCSTR Function.

    follow

    dinukak-navmate.blogspot.co.at/.../decstr-like-incstr-but-decreasing.html

    forum.mibuso.com/.../decstr-like-incstr-but-decreasing

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans