//the feature layer created in the init function propMaintLayer = new esri.layers.FeatureLayer("https://myserver.com/ArcGIS/rest/services/internal/Sanitation_Inpsection/FeatureServer/1", { mode: esri.layers.FeatureLayer.MODE_SELECTION, outFields: ['OBJECTID','PointID','Date','MaintType']}); //and the function called when a related record is clicked function selectRelated(objID){ var flQuery = new esri.tasks.Query(); flQuery.where = "OBJECTID = " + objID + ""; flQuery.returnGeometry = "false"; propMaintLayer.selectFeatures(flQuery,esri.layers.FeatureLayer.SELECTION_NEW,function (selection) { var layerInfos = [{'featureLayer':propMaintLayer, 'showAttachments':false, 'isEditable': true, 'fieldInfos': [ {'fieldName': 'OBJECTID', 'isEditable':false, 'tooltip': 'Object ID', 'label':'Object ID:'}, {'fieldName': 'Date', 'isEditable':true,'tooltip': 'Inspection Date MM/DD/YYYY','label':'Date:'}, {'fieldName': 'MaintType', 'isEditable':true, 'label':'Maintenance Type:'}, {'fieldName': 'PointID', 'isEditable':false, 'tooltip': 'Foreign key', 'label':'Foreign Key:'}, ]}]; attInspector = new esri.dijit.AttributeInspector({ layerInfos:layerInfos}, dojo.create("div",{id:"relateDiv"},"liRelate" + objID,"last") ); } ); }
//global variable for the related record feature layer relatedRecordMaintLayer = new esri.layers.FeatureLayer("https://myserver.net/ArcGIS/rest/services/internal/Sanitation_Inpsection/FeatureServer/1", { mode: esri.layers.FeatureLayer.MODE_SELECTION, //QUERY_SELECTION is working as well outFields: ['OBJECTID','PointID','Date','MaintType'] }); ....... //I am able to display the key field for the related record in a table, and this is the function to show the attribute inspector for the related record that is clicked on in the table. function showRelated(objID){ var flQuery = new esri.tasks.Query(); flQuery.where = "OBJECTID = " + objID + ""; flQuery.returnGeometry = "false"; propMaintLayer.selectFeatures(flQuery,esri.layers.FeatureLayer.SELECTION_NEW,function (selection) { var layerInf = [{'featureLayer':propMaintLayer, 'showAttachments':false, 'isEditable': true, 'fieldInfos': [ {'fieldName': 'OBJECTID', 'isEditable':false, 'tooltip': 'Object ID', 'label':'Object ID:'}, {'fieldName': 'Date', 'isEditable':true,'tooltip': 'Inspection Date MM/DD/YYYY','label':'Date:'}, {'fieldName': 'MaintType', 'isEditable':true, 'label':'Maintenance Type:'}, {'fieldName': 'PointID', 'isEditable':false, 'tooltip': 'Foreign key', 'label':'Foreign Key:'}, ]}]; attInspector = new esri.dijit.AttributeInspector({ layerInfos:layerInf }, dojo.create("div",{id:"relateDiv"},"liRelate" + objID,"last") ); } ); } }
Sebastian,
I have a few questions as I am super new to the Javascript world. I am working on a project where the user needs to find an incident by either searching for a request id or a logger's name, then log follow up records to an incident, and once that incident is resolved change the status on the feature to closed. From what I gather above and figuring out what javascript I can, your code is meant to search for something, update a feature's attributes, as well as create new related records. Is that correct?
Your code is the closest I have come to seeing something like what I want to do. How hard would it be to modify what you already wrote to fit the scenario I listed above? Basically one feature class with one related table for records, with the ability to edit the feature class and add new related records. While having the ability to search for the incident.
Suggestions would be most helpful.
Thank you
David
David,
At the time that I created that web application, there was no functionality to edit related records. Now the javascript API has a sample for querying and editing related records. Also, you might be able to use Collector if it meets your needs. Here is a blog post on related records for Collector. You might even be able to use the Web Appbuilder, but I'm not sure if the edit widget supports related records yet. In any case, I would use one those three solutions, rather than trying to wade through my rather messy javascript which is based on a very old version of the API.
Regards,
Sebastian Roberts