Good morning,
Can we add an attribute rule to a hosted feature class to calculate the next value for an ID?
I created a feature class in ArcGIS Pro with an attribute rule to Auto Increment the ID, and published the feature class as a hosted feature in AGOL, but the rule is missing.
Thanks
My information might be out of date, since I haven't followed the most recent changes to AGOL, but I don't think Attribute Rules and NextDatabaseSequence are currently supported in AGOL.
You could maybe create a workaround by embedding an auto-calculated script that reads all existing records and returns the next ID, but then I think the Attribute Rule in Pro might start returning duplicates, since it doesn't check existing records to make sure the value is unused.
You might want to check out these two submissions to the AGOL Ideas board:
I think the other official suggestion right now is to host in Enterprise and REST out to AGOL, if memory serves.
Thanks @MErikReedAugusta
How do you create an auto-calculated script in AGOL?
Although I haven't done this myself, I think you could do it with a webhook. Write the webhook to capture the feature's details, perform the calculation, then write back to it. There's going to be a brief delay and I'm not sure you'd see the calculation reflected immediately.
Here's a blog post on setting up webhooks in AGOL:
If editing is primarily taking place through web map forms, you can do calculations in those as well, although they won't be applied if editing occurs in other contexts (like REST API calls).
Quick addendum, another option is to used a scheduled notebook to set IDs on all features that currently have null values, however this involves a significant delay and wouldn't be appropriate for time-sensitive workflows.