Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Can we add a string variable to have an increment using x++?

(0) ShareShare
ReportReport
Posted on by 508
Hello guys,
 
Need help on some logic, for example when I have a variable like /TEST-0001/, can we make a code to have it increase ?
So the end result, I will have an increase variable like /TEST-0002, TEST-0003, TEST-0004, and so on/. For how many increment, I add an input for user to specify how many they need.
 
FYI, for an odd reason, I can't use number sequence for this activity.
 
Thanks.
  • Verified answer
    Arunraj Rajasekar Profile Picture
    Arunraj Rajasekar 1,731 on at
    Can we add a string variable to have an increment using x++?
     
    Hi,
     
    I have explained the logic in four steps below. You can simplify and improve it as per your business requirement. Validate before saving the result to table to avoid duplicate records.
    1. Read the string value in a buffer, something like this 
      str testStr = TEST-0002;
    2. Use substring to get the number and convert it to number
      int incNum = str2int(subStr(testStr,5,99);
    3. Then increment the number 
      incNum = incNum +1;
    4. convert the number again to string, concatenate it back and save it.
     
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,661 Super User 2024 Season 2 on at
    Can we add a string variable to have an increment using x++?
    Hi Ken,
     
    When you have a main project, you can specify a format that will be added to the main project when creating sub projects. 
     
    Assume you have project 1001 and a format set as -###. When creating subprojects for this project, it will create them while replacing the hash symbols with numeric values. E.g.
     
    1001-001
    1001-002
    1001-003
    etc.
     
    A sub for another project will start at 1 again. It does not require setting up a number sequence.
     
    You can find the logic in the method generateNextSubProjectId on the table ProjTable
  • Ken Manhattan Profile Picture
    Ken Manhattan 508 on at
    Can we add a string variable to have an increment using x++?
    Hi Bharani,
     
    and your suggestion is ?
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    Can we add a string variable to have an increment using x++?
    Yeah you can just increment the digit value and again concat it to the string. This doesn't require number sequence. But based on your requirement we can suggest how to increment.
  • Ken Manhattan Profile Picture
    Ken Manhattan 508 on at
    Can we add a string variable to have an increment using x++?
    Hi Andre,
     
    I'm sorry, but what "subproject" you meaning ? And this is not handled by number sequence ? cause what I look is not the one using number sequence setup.
    Thanks
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,379 Most Valuable Professional on at
    Can we add a string variable to have an increment using x++?
    I would parse the string to the number and the prefix, increased the number (++ operator) and composed the string again.
     
    Increasing a character code is technically possible, but it's not what you want. For example, in ASCII, the next character after '9' is ':'. It can't be '10', because that's a string consisting of two characters, not a character, therefore it's a completely different thing.
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,661 Super User 2024 Season 2 on at
    Can we add a string variable to have an increment using x++?
    Hi Ken,
     
    Yes this is possible. I'm not able to directly paste an example, but you can find one yourself in the application. When creating sub-projects, a string gets incremented. You can do some reverse engineering to find out this is done in the standard.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans