How to create readonly field with default value

452
1
Jump to solution
05-03-2019 06:34 AM
DonMorrison1
Occasional Contributor

I have a feature class (SQL Server table) that contains data from multiple clients (organizations). I want to expose the data, but control access so an org can only view/update its own data. I've created a flow as shown below (this is done for each org)

  1. Create a layer file (.lyrx) with a query definition against the single table to pull out the org's data (the table has a key field - ORG_ID)
  2. Create a project (.aprx) based on the layer file and publish a REST endpoint on my ArcGIS server
  3. Create a feature service in ArcGIS Online based on the REST endpoint
  4. Share the feature service into an AGOL group where I have invited only members of the organization
  5. From that feature service I build web maps, web mapping apps, surveys etc and share them into the group also

This all works very nicely and I've scripted it so it is easy to onboard new orgs. But I have one problem I can't solve.  I need to make sure that the ORG_ID is not altered for existing records (I think I can accomplish this by hiding the field in the layer definition) and I need to make sure that the ORG_ID is correct on added records. I've looked into SOE's and DB triggers. The trouble there is there isn't enough context to know what the value is supposed to be. I tried many other approaches but nothing has worked completely.   Any suggestions? 

0 Kudos
1 Solution

Accepted Solutions
DonMorrison1
Occasional Contributor

Well I came up with a very dirty solution on this that seems to work and I'll go with it until something more elegant comes up.  I create my REST service names such that I can derive the desired key field values from them. Then I wrote an SOI that:

  1. intercepts all "applyEdit" REST requests
  2. Gets the service name it's running on behalf of (from the server environment "CfgName" property) and derives the desired key field value. For example if the service name is "COMPANYA_WIDGETS", the derived key value is "COMPANYA"
  3. Digs into the received json and sets the key field is being set to the desired value before passing it on to be processed by the server.  I simply did a regular expression replacement like this:
string pattern = "\"Org_ID\":\"[^\"]*\",";
operationInput = Regex.Replace(operationInput, pattern, "\"Org_ID\":\"" + orgID + "\",");

View solution in original post

0 Kudos
1 Reply
DonMorrison1
Occasional Contributor

Well I came up with a very dirty solution on this that seems to work and I'll go with it until something more elegant comes up.  I create my REST service names such that I can derive the desired key field values from them. Then I wrote an SOI that:

  1. intercepts all "applyEdit" REST requests
  2. Gets the service name it's running on behalf of (from the server environment "CfgName" property) and derives the desired key field value. For example if the service name is "COMPANYA_WIDGETS", the derived key value is "COMPANYA"
  3. Digs into the received json and sets the key field is being set to the desired value before passing it on to be processed by the server.  I simply did a regular expression replacement like this:
string pattern = "\"Org_ID\":\"[^\"]*\",";
operationInput = Regex.Replace(operationInput, pattern, "\"Org_ID\":\"" + orgID + "\",");

View solution in original post

0 Kudos