Hi Jeff, > If ((JSON Stringify($fieldPtr->))#(JSON Stringify(Old($fieldPtr->))))
This only works if the order of the keys in the object stays the same which may not be true depending on how you change the object. I’ve pasted in a method below that you can use to compare two objects which don’t care about the order of keys. I use it in a similar situation to what you are doing and it works well. The method name is “OBJ_IsEqual”. It calls itself, so if you use a different name make sure you change that in the code. Vincent de Lachaux posted the original code which I then stole. :-) -- Cannon.Smith Synergy Farm Solutions Inc. Hill Spring, AB Canada 403-626-3236 <[email protected]> <www.synergyfarmsolutions.com> //Compares two objects. If they are the same (ie. they have exactly the same elements and values), //the method returns true. Thanks to Vincent de Lachaux for the original code which has been changed //slightly to more closely match my style. C_OBJECT($1;$oFirst) C_OBJECT($2;$oSecond) C_BOOLEAN($0;$fIsEqual) $oFirst:=$1 $oSecond:=$2 $fIsEqual:=False //Default to false C_LONGINT($x;$y;$lFirstItemCount;$lSecondItemCount;$lFirstPropertyCount;$lSecondPropertyCount) ARRAY LONGINT($alFirstType;0) ARRAY TEXT($atFirstProperty;0) ARRAY LONGINT($alSecondType;0) ARRAY TEXT($atSecondProperty;0) OB GET PROPERTY NAMES($oFirst;$atFirstProperty;$alFirstType) OB GET PROPERTY NAMES($oSecond;$atSecondProperty;$alSecondType) $lFirstPropertyCount:=Size of array($atFirstProperty) $lSecondPropertyCount:=Size of array($atSecondProperty) If ($lFirstPropertyCount=$lSecondPropertyCount) //They won't be equal if they have different property counts If ($lFirstPropertyCount>0) //Sort arrays because the properties could be in a different order SORT ARRAY($atFirstProperty;$alFirstType) SORT ARRAY($atSecondProperty;$alSecondType) //Now compare each property For ($x;1;$lFirstPropertyCount) Case of : ($atFirstProperty{$x}#$atSecondProperty{$x}) //Check property name $fIsEqual:=False : ($alFirstType{$x}#$alSecondType{$x}) //Check property type $fIsEqual:=False : ($alFirstType{$x}=Is object) //compare the two objects $fIsEqual:=OBJ_IsEqual (\ OB Get($oFirst;$atFirstProperty{$x};Is object);\ OB Get($oSecond;$atFirstProperty{$x};Is object)) : ($alFirstType{$x}=Object array) //In an object array we can massage all the array types back into text except object themselves. //So we get two sets of arrays, one text and the other objects. Then we can deal with either kind //as we walk through each element. ARRAY OBJECT($aoFirst;0) //Reset arrays ARRAY TEXT($atFirst;0) ARRAY OBJECT($aoSecond;0) ARRAY TEXT($atSecond;0) OB GET ARRAY($oFirst;$atFirstProperty{$x};$aoFirst) //Get text and object types OB GET ARRAY($oFirst;$atFirstProperty{$x};$atFirst) OB GET ARRAY($oSecond;$atFirstProperty{$x};$aoSecond) OB GET ARRAY($oSecond;$atFirstProperty{$x};$atSecond) $lFirstItemCount:=Size of array($aoFirst) $lSecondItemCount:=Size of array($aoSecond) If ($lFirstItemCount=$lSecondItemCount) For ($y;1;$lFirstItemCount;1) If ((OB Is defined($aoFirst{$y})) & (OB Is defined($aoSecond{$y}))) //If they are both objects $fIsEqual:=OBJ_IsEqual ($aoFirst{$y};$aoSecond{$y}) Else //Compare text $fIsEqual:=($atFirst{$y}=$atSecond{$y}) End if If ($fIsEqual=False) $y:=$lFirstItemCount+1 //Abort loop End if End for Else $fIsEqual:=False End if Else //For any other object type, we simply compare the values $fIsEqual:=(OB Get($oFirst;$atFirstProperty{$x})=OB Get($oSecond;$atFirstProperty{$x})) End case If ($fIsEqual=False) $x:=$lFirstPropertyCount+1 //Abort loop End if End for Else //If there are not elements in either one, they are both equal $fIsEqual:=True End if End if $0:=$fIsEqual ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

