You are viewing limited content. For full access, please sign in.

Question

Question

Autogenerate number from the date and initials of name and surname.

asked on August 30, 2023

Hello,
I need to automatically fill in a field in which an alphanumeric number will be autogenerated taking into account an initial suffix that does not change and then it would consist of the date without the divisions / between the month, day and year and then the initials of the name and the last name.

In the form I use a field to take the name called First Name and I use another field called Last Name for the last name.

The field to store the number that I need is called Request Number, which should be automatically filled taking into account the following:
Example of the desired format in which it should be stored: RTN-08302023-LM

Where the first 3 letters (RTN) will never change, they will always be fixed. what follows after the - would be the current date (08/30/2023)without the separators / or - (08302023)would be to place the continuous date without separators and then what follows after the - (LM)would be the first initial letter of the First Name and Last Name.

Any idea how to do this?

Thank you.

LSF V: 11

0 0

Answer

SELECTED ANSWER
replied on August 30, 2023

After doing some revisions in some posts, I found this answer to a similar problem

 

https://answers.laserfiche.com/questions/115908/Format-token-datetime

 

and following those steps I found a solution, which may not be the best practice, but for now it works for me, I'm sharing it here in case someone else needs it.

Create a text field and in the Advanced section (calculation/formula) I put the following:

=CONCATENATE("TRN-") & RIGHT(CONCATENATE("0",MONTH(TODAY())),2) & RIGHT(CONCATENATE("0",DAY(TODAY())),2) &YEAR(TODAY()) & CONCATENATE("-",LEFT(Submitted_by,1),LEFT(submitted_by_last_name,1))

And I was able to achieve the result I expected, I don't know if someone can provide a better solution, I assume so, but well, here I leave this humble solution.

rn.png
rnf.png
rn.png (2.67 KB)
rnf.png (32.96 KB)
0 0
replied on August 30, 2023

Please note that users with the same first and last initial would get the same request number from this pattern if submitting on the same day.

2 0
replied on August 30, 2023 Show version history

I second Miruna's warning. If "Hector Hernandez" and "Hilario Hernandez" make requests the same day, the outputs won't be unique and you'll have a collision. 

Two alternative suggestions:

  1. Use the Forms instance ID variable as the unique component. Those numbers are sequentially generated and guaranteed to be unique within a Forms database. 
  2. Use a SQL lookup to trigger a SQL Stored Procedure that generates and returns a unique number.

You can see some past Answers discussions here:

And a walkthrough for both approaches here:

2 0
replied on August 30, 2023

Interesting observation. Let me consult with the client about that observation to see what alternative can be applied for cases like that.

Thank You Miurna's and Samuel

1 0
replied on August 30, 2023 Show version history

We have reached a consensus. At the moment, the Request Number will remain the same, except that when saving it in the repository, the name of the file that is planned to be named is the Request Number, and the ID of the Instance will be added to differentiate them within the repository. 

Some like this: {/dataset/Request_Number}-{/dataset/_instance_id}-{/dataset/Decision}


In this case we cannot add a consecutive or another variant to that Request Number in the form field, it must be that way according to the client's requirements, despite the logic indicating otherwise.

Thanks to the observation that you alerted us, we were able to minimize the risk of duplicates and future errors when saving the file in the repository.

Thank you

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.