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

3539
14
Jump to solution
11-02-2017 02:11 PM
Trippetoe
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.

0 Kudos
1 Solution

Accepted Solutions
Trippetoe
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
JayantaPoddar
MVP Esteemed 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.



Think Location
Trippetoe
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.  

0 Kudos
shan_sarkar
Occasional Contributor III

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


~Shan
0 Kudos
Trippetoe
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? 

0 Kudos
shan_sarkar
Occasional Contributor III

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


~Shan
Trippetoe
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

0 Kudos
ShanaGail1
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

0 Kudos
Trippetoe
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 

0 Kudos
ShanaGail1
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.

0 Kudos