I have a form used for adding new sites to our hosted feature layer. I'd like to make some of the attributes read only if the user is editing an existing site, but make them all editable if the user is creating a new site. Any suggestions on how to set this up?
If you don't have a field calculation to deal with it is fairly simple.
Create a editable expression that examines the edit context profile variable:
Arcade Constraint Profile Documentation
Create Editable Expression Documentation
// prevent editing if this is an update, else allow editing
if ($editcontext.editType == 'UPDATE') {return false};
return true
If you have a field calculation on the same field and you wish to preserve the value as calculated on INSERT you'll need to be more creative to stop the calculation from updating its value.
In this case, all the work is done in calculate expression rather than the editable expression since on INSERT or UPDATE the field is not editable. On UPDATE we need to preserve the value calculated on INSERT.
It would look something like the following:
// This example calculation is occuring on field rsrc_previous_feature_info
function getOriginalSelf() {
/* If state is UPDATE and the current service number hasn't changed return self
else return nothing. */
if ($editcontext.editType == 'UPDATE') {
if (!IsEmpty($originalFeature)) {
var oSelf = $originalFeature.rsrc_previous_feature_info;
var oServiceNumber = $originalFeature.service_number;
if (oServiceNumber == serviceNumber) {return oSelf};
};
};
};
var serviceNumber = $feature.service_number;
var originalSelf = getOriginalSelf();
/* if nothing is returned, then this is an INSERT, else
exit early by returning the original value here */
if (!IsEmpty(originalSelf)) {return originalSelf};
// continue the calculation for an INSERT below...