Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Standard way to reverse INCSTR Function.

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

  • Verified answer
    keoma Profile Picture
    keoma 32,675 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
    Ashwini Tripathi 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
    keoma 32,675 on at

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans