0

How to create a field that consists of the last four digits of another field.

This question is probably more basic than it sounds.

I want to take the last four digits/characters of a number and use them as the content in another field. The original number will be more than 4 digits but could vary in total length.

Preface: I'm less than a novice at REGEX - I suspect from searching around that using "\d{4}$"  would get me the answer I want but I don't see how to use the REGEX expression to create the value in the second field based on the value in the first field.

Any gudiance and/or handholding would be greatly appreciated.

Thanks

5 replies

null
    • Sean
    • 3 yrs ago
    • Reported - view

    You're almost there. You can use this in the "Trigger after update" of source number field or in a button...

     

    let lastFour := extractx(text('Num1'), "\d{4}$");
    'Num2' := number(lastFour)

    • Sean
    • 3 yrs ago
    • Reported - view

    The single quotes aren't necessary. I change the field names and forgot to delete the single quotes.

    • Dorich
    • 3 yrs ago
    • Reported - view

    @Sean:

    Thanks, that's very helpful.

    I ran into a couple of issues:

    The code works as expected when attached to a Button.

    However, using the same code on "Trigger after update" didn't produce any results.

    Also Ninox seems to want the single quotes around the field names?

    However, as noted this code works on a Button and so problem solved. Thanks again.

    • Sean
    • 3 yrs ago
    • Reported - view

    If a field name has a space in it, single quotes are required. When I tested the code, I used it in "Trigger after update". Are your fields in the same table?

    • Dorich
    • 3 yrs ago
    • Reported - view

    @Sean:

    Thanks.

    Got it on the field name.

    The "Trigger After Update" was caused by my incorrect usage. Now fixed and working perfectly.

Content aside

  • 3 yrs agoLast active
  • 5Replies
  • 465Views