Confirmation Number Generator Snippet

Overview

The Confirmation Number Generator snippet creates a unique code for each user. The user's code won't change. So, you'll use this snippet for processes done once, like an end-user signing up or creating an account. This snippet does calculations behind-the-scenes and doesn't have any elements visible in Express View. So, you'll likely use it as part of a larger remote execute module.

Why might you use the Confirmation Number Generator snippet? The snippet is a great fit if you want each end-user to get a confirmation number for completing a process. You'll likely use it as part of a larger submission process. For example, you may have an application where end-users sign up for a new account. Let's say they run into an issue in your application. They can reach out and reference their unique confirmation number. This snippet is ready-to-use and easily fits as a part of a larger API (application programming interface) remote execute module.

Here's how the snippet looks in the Module Builder:

What You'll Learn

In this article, you'll learn:

Adding the Snippet

Once you have this snippet in your environment, you can add it to your module. To add the Confirmation Number Generator snippet to your module:

1. In the left sidebar of the Module Builder, click the Snippets button.
2. Enter Confirmation Number Generator in the search bar.
3. Drag and drop the Confirmation Number Generator snippet onto your canvas.
4. Save your module.

This snippet is ready-to-go right off the shelf. Just add it to your current configuration.

How the Snippet Works

Every user in an Unqork environment has a user ID that's unique to them. The Confirmation Number Generator snippet uses a user's ID to create a confirmation number unique to that user. Here's how the components in the snippet work together.

The initHash Initializer runs on a new submission. So, when the page loads or if the module executes remotely, this Initializer runs. It fires the calcSetHashInput Calculator. The Calculator pulls the current user's ID and outputs it to the intakeToHash Hidden component.

The initHashUserPlugin Initializer watches the intakeToHash field, waiting for an extracted user ID. Once the Initializer sees the ID, it triggers the pluginHashConfId Plug-In. This Plug-In takes the user ID from intakeToHash and maps it to an input field called string. The Plug-In then executes an Unqork service called hashString. This service hashes the user ID and outputs a long string of numbers and letters to the hashIntake Hidden component. The hashed string is unique to the user ID and takes the place of that user ID. This process keeps your end-user's information safe.

From there, the calcIntakeSubset Calculator takes the last 12 digits of the hashed string. Since the hashed user ID can be very long, the Calculator cuts it down to 12 digits. Then, it outputs those digits to the confirmationNumber Hidden component. This Hidden component stores the 12-digit confirmation number to the database.

Testing the Snippet

So, how can you test that your Confirmation Number Generator snippet works? You can test it using Server Side Execution.

1. Click the Server Side Execution button at the top of your module in the Module Builder.
2. Click Execute.
3. Check the Response Body for the results of your server-side execution.

Here's an example of a response:

And here's what you can see in this response. The intakeToHash response shows the user ID. The hashedIntake response shows the translation of that user ID into a unique hashed string. Finally, the confirmationNumber response takes the last 12 digits of the hashedIntake, which is the user's confirmation number

Because each user has 1 unique user ID, you'll get the same confirmation number if you do a second server-side execution of your module. Remember that this snippet best fits a process that happens once, like setting up an account.

Removing the Snippet

Removing a snippet from your module is easy. To remove the Confirmation Number Generator snippet:

1. In the Module Builder, hover over the panelConfirmationNumberGenerator Panel.

A 5-button toolbar appears above the component on hover-over.

2. Using the toolbar, click the (Remove) button.
3. Save your module.