function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ryan ThomasRyan Thomas 

Javascript OnChange event to concatenate fields to check for uniqueness

I am looking to perform a check for uniqueness on task records.  In my scenario, uniqueness is defined by a combination of:
  • User ID (CreatedBy)
  • Date (ActivityDate)
  • Task type (custom picklist)
For example:
User ID:       005U0000004qTC1
Date:           2015-08-08
Task Type:  Visit
Concatenated Text:  005U0000004qTC12015-08-08Visit

Since Salesforce doesn't offer uniqueness checks on formula fields, I cannot use a formula field even though it concatenates effectively.

What I'd like to do is create a JavaScript event (OnChange event of the task type or activity date) to populate a custom text field with a concatenation of those three values, so that upon saving of the record, the native uniqueness check on a text field can look for duplicates.

I'm not looking for someone to spoon feed me the code.  I just want to know if it's feasible.
Anirudh SinghAnirudh Singh
Hello Ryan,

I have an alternate for you, without using JavaScript.
Its simple configuration with no headaches.


Desired Output: A text field with Concatenated Field Values. A combination of: User ID (CreatedBy), Date (ActivityDate), Task type (custom picklist).

Please see the steps below:
1. Create a Formula Field to Concatenate these 3 fields say its name be 'Concatenated Value'.
2. Create another field of DataType 'Text' with 255 characters say its name be 'Unique Concatenated Value'.
3. Create a Workflow Rule on the Object, give the Evaluation Criteria: "Evaluate the rule when a record is created, and every time it’s edited".
Rule Criteria: Concatenated Value NOT EQUAL TO null
Create a Field Update. This field update will update the 'Unique Concatenated Value' with the value of the formula field 'Concatenated Value'.

Your job is done, you have your unique value text field.

Now, you can use this field to look for duplicates.


Please let me know if this helps.
If yes, please mark the question as Solved.


Thanks and Regards,
Anirudh Singh
Ryan ThomasRyan Thomas
Hi Anirudh,
Thank you for your feedback, however, your focus seems to be on using the unique value to search for duplicates (reactive) rather than the prevention of creating a duplicate record (proactive). The workflow you mention will run after the record is saved, at which point you could have already created a duplicate.
I want the system to check for uniqueness prior to the saving of the record using Salesforce's uniqueness check, which is why I need a field to capture the concatenation while in edit mode.