How do I populate createdby/modifiedby fields when creating new features?

829
1
Jump to solution
03-13-2020 03:08 PM
CoryDavis
New Contributor III

I have an app which uses the iOS Runtime SDK v100.6 which loads feature services from an on-premise installation of Portal for ArcGIS v10.7.1. The feature layers were loaded onto the map directly from their urls without requiring the user to authenticate with the portal. When the user creates a new feature and applies the edits, I can view the new feature in ArcGIS Pro, but the CREATIONUSER and LASTUSER fields both have the value "Esri_Anonymous".

attribute table for feature class showing "esri_anonymous" where username should go.

 I recognized that it is necessary to log the user into the portal before making edits, so I modified the initialization to do so (Slight variation from Esri documentation😞

override func viewDidLoad() {
    self.portal = AGSPortal(url: NSURL(string: "https://mycompanysserver.com/portal")! as 
    URL, loginRequired: true)
    self.portal?.load(completion: { (err) in
        if let error = err {
            print(error)
        }
        else {
            print("Successfully logged into portal.")
            self.addOperationalLayersFromPortalItem()
        }
    }
}

func addOperationalLayersFromPortalItem() {
    var loadedCount = 0
    DispatchQueue.main.async {
        SVProgressHUD.showProgress(0, status: "Loading Layer \(loadedCount)/25")
    }
        
    self.featureLayers.removeAll()
    self.allLayers.removeAll()
        
    if let portal = self.portal {
        if let user = portal.user { //If logged in successfully
            var loadedCount = 0
            DispatchQueue.main.async {
                SVProgressHUD.showProgress(0, status: "Loading Layer \(loadedCount)/25")
            }
            let featureStagingService = AGSPortalItem(portal: portal, itemID: self.featureStagingServiceId)
            for i in 1 ... 25 {
                let layer = AGSFeatureLayer(item: featureStagingService, layerID: i)
                    
                featureLayers.append(layer)
                allLayers.append(layer)

                layer.load(completion: { (error) in
                    loadedCount = loadedCount + 1
                    self.updateLoadingProgress(loadedCount, outOf: 25, withMessage: "Loading Layer")
                        
                    guard error == nil else {
                        print("Error loading layer ", i, ": ", error!.localizedDescription)
                        return
                    }
                })
            }
            self.onFinishedLoading()
        }
    }
}

But loading the layers like this fails:

Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=8, NSUnderlyingError=0x2839092c0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <340D6EFF-6BD9-47E7-AD68-F9508910203E>.<115>, _NSURLErrorRelatedURLSessionTaskErrorKey=(

    "LocalDataTask <340D6EFF-6BD9-47E7-AD68-F9508910203E>.<115>"

), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://company-server-behind-firewall.com/mapgallery/rest/services/EmergencyManagement/EM_FeatureSt..., NSErrorFailingURLKey=https://company-server-behind-firewall.com/mapgallery/rest/services/EmergencyManagement/EM_FeatureSt..., _kCFStreamErrorDomainKey=12}

The instance of portal is using a reverse-proxy, and although I'm using the publicly accessible urls to reach the feature services, they are returning the internal urls behind the firewall and the http request fails.

With this setup, what is the correct way to load portal items as a logged in user?

0 Kudos
1 Solution

Accepted Solutions
CoryDavis
New Contributor III

Turns out it is necessary to secure any services where editor tracking is enabled. There is no way to keep it available to everyone and for new features to populate the createdby/modifiedby fields. After re-publishing the service, but only making it available to authenticated users, the user id was recorded in these fields.

View solution in original post

0 Kudos
1 Reply
CoryDavis
New Contributor III

Turns out it is necessary to secure any services where editor tracking is enabled. There is no way to keep it available to everyone and for new features to populate the createdby/modifiedby fields. After re-publishing the service, but only making it available to authenticated users, the user id was recorded in these fields.

0 Kudos