How can we generate unique Id without making any DB calls i.e directly from SAIL form

Certified Associate Developer

Hi ,

 

I have a scenario, where I have 2 buttons on my form: Add and Submit.

1) A user has to add details(say for example employee details) before submitting the form.

2)Use can add more than 1 employee details. Once these details are added they are displayed in a new grid in the same form.

3) Once the user clicks on Add button , the details get displayed in new grid, but at the same time I need to generate unique Id for each new addition. 

I will remain on the same form until and unless I submit it. Before submitting the form I need t generate unique Ids(say employee Id).

How this can be done from SAIL side. I do not want DB calls, as this might impact the performance?

 

 

  Discussion posts and replies are publicly visible

  • Hello Diptis,

    I would suggests you to handle by doing DB calls.
    It will avoid you having constraint issues if two or more people work at the same time with the form as i believe there is no way to maintain the track on the IDS generated in the UI.


    If you still want to follow this approach what i think you can do is:
    1.- Create a constant which will keep track on the IDS.
    2.- Use the constant and +1 for each element you need.
    3.- While you click submit you need to update the constant in the process model to the last number you used.

    If more than 2 people use this screen at the same time the IDS are going to be the same and it will try to persist the same ids causing it to crash.

    I hope this gives you a better perspective i also believe some one might have another approach which might help you.
  • Does the Employee ID(s) have to be unique in relation to Employees that already exist in your database? If that is the case, I don't think there is a way to avoid doing atleast one database call to retrieve the max employee ID that already exists. Even if you decide to go with this approach, you can run into collisions if more than one user is attempting to add new employees (e.g. User A and User B initiate the action to add employees at the same time, they both do one query to grab the max employee ID which is currently equal to 10, they both end up creating an Employee with ID 11 at the same time).

    It might be simpler to display the IDs upon submission and display temporary IDs when the form hasn't been submitted. E.g. - Clicking Add Button displays details and "Employee 1"; or maybe you don't need to display an ID, you display the name of the employee instead (already included in details). Then when you submit you can display a confirmation screen which displays the newly generated IDs outputted from your write to (multiple) data store entity node.
  • I'm not sure how this will impact the performance?

    The best option is to save the employee details using the start process when the user clicks the 'Add' button. You can configure it to start a process that saves the employee to the database and returns the auto-generated primary key to the SAIL form.

    You can also utilize a constant, but just be aware that it will not always be sequential if you run into race conditions. You can use the constant by running the 'increment constant' smart service node and saving that value as your unique id.
  • hi  - 

    Look at this play in the Appian Playbook: Generating GUIDs.

    It doesn't require a db call. Perhaps that will help.

     

  • Hi Jose Cavazos (josec0002)  -

    Incrementing constants isn't as fashionable today as it was in the past.

    While it's technically possible, it's not the best solution as too much of this practice can lead to unexpectedly high memory utilization as the versions of the constant grow.

    Please have a look at this playbook play for generating guids.