How to set two fields as unique identifier for a record

loteodor
Kilo Contributor

Hi,

I want to set two fields as unique identifier for   a record of a table.

In few words, I have a table called Budget with two fields, Period (the year of the budget), and Cost Center (the cost center that is associated to the budget).

I would like to avoid the possibility to create two budget with the same Cost Center (ex. Customer Support) and Period (ex 2014).

Does it exist a way to do it without a script?

Thank you,

Lorenzo

7 REPLIES 7

A composite Index, Period + CostCenter..


Bhavesh Jain1
Giga Guru

Script is better solution for this. In case you would like to avoid script, you can create a new field called Budget with default value as javascript: (current.period+ current.costcenter)


And then make this field as unique in dictionary.


Jacob_Andersen
ServiceNow Employee
ServiceNow Employee

Lorenzo,



You have a couple of options on how to do this.   You could contact SN support regarding making a unique index on the two fields combined (composite index).   You cannot do this be adding the unique checkbox to both fields.



Your second option is to create a 'before' business rule that checks to make sure that a record with those combined values do not already exist.   If they do, setAbortAction=true and add an error message telling the user why the record would not save.



Let me know if this helps.