Inkey Solution Logo
banner

Blogs

How to Populate Prefix in AutoNumber fields based on conditions in Dynamics 365 Sales

, December 10, 2024 91 Views

Maintaining organized and meaningful data is crucial for effective management and analysis. AutoNumber fields are a popular solution for generating unique identifiers, but sometimes a simple numeric sequence isn’t enough. By adding prefixes based on specific conditions, you can enhance the context of your data, making it easier to identify and categorize records briefly. In this blog, we’ll explore one of the strategies to populate prefixes in AutoNumber fields, guiding you through the process step-by-step. Let’s dive in!

Step 1: Create an AutoNumber field with prefix and a choice field

Creating the AutoNumber Field

First, we need to create an AutoNumber field in our database. This AutoNumber will have a custom format that includes a prefix. For our initial setup, we’ll use “CS” as the prefix, which will be dynamically replaced later based on user input.

Creating the Choice Field

We created the choice field to differentiate the AutoNumber seeds based on the selected option. By providing predefined choices, such as “Cybersecurity” and “Artificial Intelligence (AI),” we can assign unique AutoNumber seeds for each option. This ensures that the identifiers generated for records in each category are distinct, aligning with the requirement to manage AutoNumber fields dynamically based on specific conditions.

  • Cybersecurity
  • Artificial Intelligence (AI)

Step 2: Setting Up Power Automate for Record Creation

Now that our fields are set up, we’ll create a Power Automate flow that triggers when a new record is created.

Creating the Cloud Flow

  • Start by creating a new cloud flow in Power Automate. Choose the option that triggers the creation of a record in your application.

  • Initialize a Variable:

After the trigger, add an action to Initialize a variable. Set the variable type to String. This variable will hold the modified AutoNumber value.

  • Split the AutoNumber Field:

Use the following expression to split the AutoNumber value based on the character “_”:

split(triggerOutputs()?['body/test_studentmajorid'],'_')

Once you split the array we’ll get the output in array, we need the zeroth index from it and replace it into the desired prefix according to condition.

  • Check the Condition for Major Selection:

Add a Condition action to check if the selected major is “Artificial Intelligence”.

 If the condition is true, set the variable to the desired prefix (for example, “AI”) followed by the index from the split AutoNumber. The resulting value will look like this: AI_<first_index>_<formatted_value>.

  • Update the Record:

Finally, use an Update record action to replace the original AutoNumber field value with the new value stored in the variable.

Once your flow is set up, you can see how the AutoNumber prefixes change based on the chosen major. Here are examples of how the records will look:

  • For a record with the major “Cybersecurity”, the AutoNumber might appear as: CS_1
  • For a record with the major “Artificial Intelligence”, the AutoNumber would change to: AI_1

This process not only automates the assignment of meaningful prefixes to AutoNumber but also enhances the organization and readability of your records based on user choices.

By following these steps, you can efficiently manage AutoNumber fields and dynamically adjust their values, making your data more intuitive and aligned with user selections.

mm

Inkey

INKEY is your solution partner.
Our focus is to deliver you in-time intelligent innovative solutions ("key") for the problems in hand. Maintaining a quality standard right from the inception of a project is our top most priority.

Our team of talented professionals will execute your projects with dedication and excellence. We take ownership and accountability for the effort that goes into meeting our client’s needs.

Years of experience and proven success of delivering innovative custom solutions.

More posts by

Leave a Reply

Your email address will not be published. Required fields are marked *

The maximum upload file size: 2 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Drop file here

Would you like to digitize your business and put it on the cloud?
Do you need clear, concise reports for your organization?