Can I set a unique index on a field in a hosted feature layer

1038
14
Jump to solution
11-02-2017 02:11 PM
Highlighted
Occasional Contributor III

I have a 'case number' field in our hosted feature layer that serves as a human-readable unique identifier. I need to prevent duplicate values being entered in that field (our current process is to run a query nightly to identify any duplicate entries).

Is there a way to set a unique index on that field? Or any other ways to guarantee uniqueness of values as the values are being entered? 

In a sort of worst case, is there a way to query the hosted feature layer before the new record (or edited record) is submitted? If the value exists, the user could be notified.

Thank you.

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor III

As an update on this thread, Esri recently added the ability to add a Unique Index on a field for a hosted feature layer.  See the help document here:  Manage hosted feature layers—ArcGIS Online Help | ArcGIS 

Search for the section header Add a unique constraint to a field

View solution in original post

14 Replies
Highlighted
Honored Contributor

Tom,

You could Add Global IDs and then publish the features. GlobalIDs uniquely identify a feature or table row within a geodatabase and across geodatabases.

Highlighted
Occasional Contributor III

Thank you for your suggestion.  We already have GlobalIds in the table. the problem is that they are not 'human readable'.  We need something that an Admin or field user can refer to when talking about the record.  Current we use something like 'i am working on case number 17-0567'.   We couldn't do that (as easily) if we were using guids.  

Reply
0 Kudos
Highlighted
Regular Contributor

Tom,

We have a similar setup where we need to generate a GISCODE field for all individual tables across the entire DB. We have a small setup wherein we generate an alpha numeric code to ensure that there is no duplicate data/codes.

So you can take 3-4 characters from the table name and concatenate it with the ObjectID. ArcGIS will take care of the OBJECTID and will ensure that there is no duplicate data.

e.g.

TABLE_1

TABLE_2

TABLE_3

I hope this helps!

~Shan

Reply
0 Kudos
Highlighted
Occasional Contributor III

Hey Shan.

Are you able to create the values like 'TABLE_1' automatically, or are they created/entered by a manual process?  Do you have a way to guarantee that they are unique? 

Reply
0 Kudos
Highlighted
Regular Contributor

Tom,

If you are using enterprise database you can use triggers to automatically populate an auto incremental value as the new record is added. 

In a database we can never save two tables with the same names and so the combination of the partial table name and the OBJECTID will always be unique. Obviously there are many such other logics that can be implemented based on your usability and requirement. 

I hope this helps!

~Shan

Highlighted
Occasional Contributor III

Hi Shan.

Using a database trigger would be my preferred alternative, but I am using a hosted feature service on AGOL. It's my understanding that we don't have the ability to set triggers within the AGOL database.  Perhaps my understanding isn't correct?

Thanks for your suggestions.

Tom

Reply
0 Kudos
Highlighted
Occasional Contributor

Hi Tom,

I followed your link and I only saw an option for adding a spatial index.  Can you do an attribute index on a hosted feature layer (AGOL)? 

Thanks,

Shana

Reply
0 Kudos
Highlighted
Occasional Contributor III

Hi Shana.   You can add a unique constraint on an attribute field.  Here's the right link:

Add a unique constraint to a field—ArcGIS Online Help | ArcGIS 

Reply
0 Kudos
Highlighted
Occasional Contributor

Hi Tom,

Maybe I'm asking questions on the wrong thread.  What I'm looking for is an attribute field index for performance purposes, not a constraint to enforce uniqueness.

Reply
0 Kudos