Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

replacing digits within a string of numbers

Featured Replies

Each customer in my database has a unique 4-digit customer number. In an invoice number, the two numbers preceding this customer number change based upon when the order was placed and how many orders have been placed in a given year (for example, Invoice #224567 would indicate the second order of 2002 for customer 4567). I want to be able to change just the second digit to reflect a third order for the year 2002 (in the example, the new invoice # would be 234567). Using "Replace" in a script doesn't seem to be the right way to go. Any suggestions?

There seems to be a fundamental limitation in the system you're envisaging, insofar as you are allowing for no more than nine orders per customer within any calendar year. I assume that your business is such that this will not be a problem?

Notwithstanding the above issue, what I suggest you do is:

1. Create a calculating field called 'CustomerYear' with the formula: CustomerID & Right(Year(InvoiceDate), 1)

2. Create a self-join relationship called 'CustomerSerial' which links the CustomerYear field to itself.

3. Create a number field called 'InvoiceSerial'

4. Create an unstored calculation field called 'NextInvoiceSerial' with the formula Max(CustomerSerial::InvoiceSerial) + 1)

5. Define InvoiceSerial as a lookup to copy values from the 'NextInvoiceSerial' field based on the CustomerSerial relationship, and set "If no exact match use" with the number 1 entered into the text box.

6. Create an unstored calculation field called 'InvoiceID' with the formula: Case(IsEmpty(CustomerID) or not IsValid(invoiceDate), "", Right(Year(invoiceDate), 1) & InvoiceSerial & CustomerID)

That's it. You need only include the 'CustomerID', 'InvoiceDate' and 'InvoiceID' fields on your layouts - the other fields operate behind the scenes.

When InvoiceDate and customerID values are entered, the appropriate Invoice ID number (with the second numeral incremented according to how many invoices have been generated for the current customer in the current year) will appear automatically in the "InvoiceID" field.

This will generate numbers from 214567 to 294567 for your first nine orders per customer per calendar year, as per your example. I'm afraid that after that, (as previously noted) things will go awry and the next number generated will be 2104567.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.