Hello GIS friends,
I have created a field called 'createddate2' and I'm trying to populate that field in Field Maps Designer using the forms option so when people create features using Field Map or web Web Map the 'created_date' value is dynamically added to the new field (createddate2) field.
I have used this '$feature.created_date' expression in the arcade editor form but it does not populate when the feature gets created. It only populates if I go back to the feature to edit and click update.
Your input will be appreciated.
Thank you,
Abi
This is what I'm using:
Solved! Go to Solution.
Hi,
Editor Tracking will systematically track who and when features were last created or edited:
If you want to manually populate a created date field, you will need to create a field and calculate it using the Form. I'm a bit confused with how many fields you have but to help break down some key concepts:
Calculating $feature.created_date will return the value from the field 'created_date'. I don't believe we have a second field here and there is just some confusion.
As Clay said, using now() or today() would be better to calculate a date. However, if you are editing the feature later on, the created date value will get overwritten by the calculation again.
So you could use the below Arcade expression. It has some additional logic to only calculate when the feature is created (INSERT). It will calculate the date and time if the user uses the form (i.e. in Map Viewer or Field Maps). It won't work if they load in the data some other way, such as ArcGIS Pro, or a map that does not have the form.
// determine our edit mode ("INSERT", "UPDATE", or "DELETE")
var mode = $editcontext.editType
// If mode is insert, return the current time. Can use today() for date only.
if(mode == "INSERT"){
return now()
}else{
// return existing value of field we are editing
return $originalfeature.createddate2
}
I would suggest using the "now()" function instead of accessing that attribute directly.
Thank you for your input. How would you use now()? Where would I put it?
Hi,
Editor Tracking will systematically track who and when features were last created or edited:
If you want to manually populate a created date field, you will need to create a field and calculate it using the Form. I'm a bit confused with how many fields you have but to help break down some key concepts:
Calculating $feature.created_date will return the value from the field 'created_date'. I don't believe we have a second field here and there is just some confusion.
As Clay said, using now() or today() would be better to calculate a date. However, if you are editing the feature later on, the created date value will get overwritten by the calculation again.
So you could use the below Arcade expression. It has some additional logic to only calculate when the feature is created (INSERT). It will calculate the date and time if the user uses the form (i.e. in Map Viewer or Field Maps). It won't work if they load in the data some other way, such as ArcGIS Pro, or a map that does not have the form.
// determine our edit mode ("INSERT", "UPDATE", or "DELETE")
var mode = $editcontext.editType
// If mode is insert, return the current time. Can use today() for date only.
if(mode == "INSERT"){
return now()
}else{
// return existing value of field we are editing
return $originalfeature.createddate2
}
Just like globalid, created_date does not get populated until the record is added to the actual service, which does not occur until you save - and if offline not until you sync. The expressions run before the save that is why its empty. As stated using now() would be the way to go.
The problem is saving did not populate it. I would have to go back and edit and update to populate it. Thanks to @ChristopherCounsell . His expression worked.
How would you write a complete expression with now()?
Thank you,
Abi
The code he posted looks pretty good to me. I would test it with Copy from existing features though too as we saw that can work differently.
Thank you for your code. it works perfectly! @ChristopherCounsell
Do you have any suggestions for Pro or other tools?
I would like to share some background information. This is a copy collaboration that allows users in ArcGIS Online to edit the service. However, when the service syncs back to the Portal, the editor tracking values in the created_user field from ArcGIS Online are overwritten with the Portal administrator's username. With your help, I can now retain the created_date value.
It would be great if Esri could not only maintain the Portal administrator's username but also preserve the editor tracking values from collaboration partners.
How would you handle records for collaboration partners?
Your insights, ideas, and assistance are greatly appreciated.
Best regards,
Abi