Field Map Form Calculation to Calculate GUID Only During Insert

373
1
Jump to solution
10-12-2022 01:35 PM
Sean_Haile
New Contributor III

I'm trying to author a Field Maps form calculation expression that will:

  1. execute only when a new feature is first created
  2. populate a GUID field (INF_GUID) with a new GUID value

Seems straightforward, but doesn't currently work for me on device. The IIf statement below is what is being used as the expression in the form calculation:

//if it's an insert, generate a new GUID value into field INF_GUID
//otherwise use existing value in field
IIf($editcontext.editType == 'INSERT', Guid(), $feature.INF_GUID)

Tested using Field Maps 22.3.1 (both iOS and Android), any assistance would be greatly appreciated!

 

0 Kudos
1 Solution

Accepted Solutions
Sean_Haile
New Contributor III

After doing further research, the original expression does correctly return a new guid value, except in the following condition: if copy feature (geom + attrs) is used in field maps, and the user then immediately  edits the geometry of the newly copied feature before saving the new feature. In this scenario, the expression still fails to generate a new guid value.

The following expression accounts for this oddity with the copy features tool:

//if it's an insert, generate a new GUID value into field INF_GUID
//otherwise use existing value in field
//but if Copy Feature tool is used in Field Maps, and then user immediately edits geometry before saving...
//then no Guid is calculated using this expression
IIf($editcontext.editType == 'INSERT', Guid(), $feature.INF_GUID)	

//the following expression accounts for this extra wrinkle with copy feature tool
IIf(($editcontext.editType == 'INSERT' || 
		($editcontext.editType == 'UPDATE' && 
			(IsEmpty($feature.INF_GUID) || $feature.INF_GUID == '{00000000-0000-0000-0000-000000000000}'))),
	(Guid()),$feature.INF_GUID)

View solution in original post

1 Reply
Sean_Haile
New Contributor III

After doing further research, the original expression does correctly return a new guid value, except in the following condition: if copy feature (geom + attrs) is used in field maps, and the user then immediately  edits the geometry of the newly copied feature before saving the new feature. In this scenario, the expression still fails to generate a new guid value.

The following expression accounts for this oddity with the copy features tool:

//if it's an insert, generate a new GUID value into field INF_GUID
//otherwise use existing value in field
//but if Copy Feature tool is used in Field Maps, and then user immediately edits geometry before saving...
//then no Guid is calculated using this expression
IIf($editcontext.editType == 'INSERT', Guid(), $feature.INF_GUID)	

//the following expression accounts for this extra wrinkle with copy feature tool
IIf(($editcontext.editType == 'INSERT' || 
		($editcontext.editType == 'UPDATE' && 
			(IsEmpty($feature.INF_GUID) || $feature.INF_GUID == '{00000000-0000-0000-0000-000000000000}'))),
	(Guid()),$feature.INF_GUID)