© 2018 Capita Business Services Ltd. All rights reserved.

Capita Education Software Solutions is a trading name of Capita Business Services Ltd. Our Registered office is 30 Berners Street, London, W1T 3LR and our registered number is 02299747. Further information about Capita plc can be found in our legal statement.

SIMS 7 - Change Tracking without change tracking

Change tracking within SIMS 7 is heavily tied to the data structures that underpin SIMS 7.  The TI Team are often presented with examples which are comprised from many different entities (tables) and have relatively high overheads if their system has to post changes which aren't changes at all.

I've been working on a proof of concept for a potential customer who expressed a need to identify changes in personnel data.  I've selected subset of the data discussed and written a report in SIMS to get the data.  In traditional TI style I then automate command reporter to get the data as an XML Document.

  <xs:schema id="SuperStarReport" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="SuperStarReport" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">


    <EthnicityCategory>White, British</EthnicityCategory>

    <ClearanceLevel>List 99 Cleared</ClearanceLevel>

I've found a number of clever web sites which will write C# classes for me simply by posting the output of the report in to a window (Please don't try that with customer data) and get some C# classes for free.

For example: Convert XML to C# Classes Online - Json2CSharp Toolkit did an OK job.  Paste in the above and get

// using System.Xml.Serialization;
// XmlSerializer serializer = new XmlSerializer(typeof(SuperStarReport));
// using (StringReader reader = new StringReader(xml))
// {
//    var test = (SuperStarReport)serializer.Deserialize(reader);
// }

public class Element { 

	public string Name { get; set; } 

	public string Type { get; set; } 

	public int MinOccurs { get; set; } 

	public string DataType { get; set; } 

	public string Prefix { get; set; } 

	public ComplexType ComplexType { get; set; } 

	public bool IsDataSet { get; set; } 

	public bool UseCurrentLocale { get; set; } 

public class Sequence { 

	public List<Element> Element { get; set; } 

public class ComplexType { 

	public Sequence Sequence { get; set; } 

	public Choice Choice { get; set; } 

public class Choice { 

	public Element Element { get; set; } 

	public int MinOccurs { get; set; } 

	public string MaxOccurs { get; set; } 

public class Schema { 

	public Element Element { get; set; } 

	public string Id { get; set; } 

	public object Xmlns { get; set; } 

	public string Xs { get; set; } 

	public string Msdata { get; set; } 

public class Record { 

	public double MultipleId { get; set; } 

	public int ID { get; set; } 

	public string ExternalId { get; set; } 

	public string NINumber { get; set; } 

	public string LegalForename { get; set; } 

	public string LegalSurname { get; set; } 

	public string Gender { get; set; } 

	public string Title { get; set; } 

	public DateTime DOB { get; set; } 

	public string EthnicityCategory { get; set; } 

	public string Initials { get; set; } 

	public string NOKFullname { get; set; } 

	public string NOKHome { get; set; } 

	public int HouseNumber { get; set; } 

	public string StaffTelephoneNumber { get; set; } 

	public string Street { get; set; } 

	public string Town { get; set; } 

	public string Postcode { get; set; } 

	public DateTime RequestedDate { get; set; } 

	public DateTime ClearanceDate { get; set; } 

	public string ClearanceLevel { get; set; } 

	public int ReferenceNumber { get; set; } 

	public double DocumentNumber { get; set; } 

	public string AuthenticatedBy { get; set; } 

public class SuperStarReport { 

	public Schema Schema { get; set; } 

	public List<Record> Record { get; set; } 

The beauty of deserialization is that you can simply remove all the stuff that you don't want from the classes and still process the same old XML with the superfluous stuff still in the source document.  So we can remove all the schema definition and fields that we don't want.  Unfortunately the website didn't quite get everything right and needed some fixing before the errors vanished...

public class Record { 

	//public double MultipleId { get; set; } 


	public Nullable<DateTime> DOB { get; set; } 

Some data items are best cast to string and dates / numbers need to be nullable in many cases but it takes the back ache out of the job. It even gives you the code to deserialize the XML in the header.

public static bool Go()
            XmlDocument doc = new XmlDocument();
            doc = SIMSReportingEngine.ReportingEngine.Run("StaffChecks", ".", "engga", "blacka", "abcd");
            XmlSerializer serializer2 = new XmlSerializer(typeof(Contracts.Basic.SuperStarReport));
            ontracts.Basic.SuperStarReport reportInfo = null;
            using (StringReader reader = new StringReader(doc.InnerXml))
                reportInfo = (Contracts.Basic.SuperStarReport)serializer2.Deserialize(reader);
            // Load today's records
            Dictionary<string, Contracts.Basic.Record> Today = new Dictionary<string, Contracts.Basic.Record>();
            foreach (Contracts.Basic.Record r in reportInfo.Record)
                Today.Add(r.MultipleId, r);
            // Load Yesterday's records
            Dictionary<string, Contracts.Basic.Record> Yesterday = new Dictionary<string, Contracts.Basic.Record>();
            XmlDocument dYesterday = new XmlDocument();
            Contracts.Basic.SuperStarReport reportInfoYesterday = null;
            using (StringReader reader = new StringReader(dYesterday.InnerXml))
                reportInfoYesterday = (Contracts.Basic.SuperStarReport)serializer2.Deserialize(reader);

            foreach (Contracts.Basic.Record r in reportInfoYesterday.Record)
                Yesterday.Add(r.MultipleId, r);
            // 4 different ourcomes are possible - create a dictionary of each.          
            Dictionary<string, Contracts.Basic.Record> New = new Dictionary<string, Contracts.Basic.Record>();
            Dictionary<string, Contracts.Basic.Record> Changed = new Dictionary<string, Contracts.Basic.Record>();
            Dictionary<string, Contracts.Basic.Record> Removed = new Dictionary<string, Contracts.Basic.Record>();
            Dictionary<string, Contracts.Basic.Record> UnChanged = new Dictionary<string, Contracts.Basic.Record>();
            // See what belongs in each.
            foreach (Contracts.Basic.Record r in Today.Values)
                Contracts.Basic.Record old = null;

                if (Yesterday.TryGetValue(r.MultipleId, out old))

                    // Found it.
                    if (! r.Equals(old))
                        // Add it to the list of changes.
                        Changed.Add(r.MultipleId, r);
                        // remove it from the old list
                        UnChanged.Add(r.MultipleId, r);
                        // remove it from the old list
                    // it's new.
                    New.Add(r.MultipleId, r);

            foreach (Contracts.Basic.Record r in Yesterday.Values)
                // Any left have been removed.
                Removed.Add(r.MultipleId, r);
            return true;


All looks fairly simple but requires an additional tweak to work..

Two objects in c# are only the equal if they occupy the same memory:
Record A = new Record();
A.Name = "SIMS";
Record B = new Record();
B.Name = "SIMS";
if (A == B)
.. surprisingly this is false!

In order to make it work here, i had to override equals as follows:

public class Record
		public override bool Equals(System.Object obj)
			//If the obj argument is null return false  
			if (obj == null)
				return false;
			//If both the references points to the same object then only return true  
			if (this == obj)
				return true;

			//If this and obj are referring to different type return false  
			if (this.GetType() != obj.GetType())
				return false;

			//Compare each field of this object with respective field of obj object  
			Record test = (Record)obj;
			if (
				this.MultipleId == test.MultipleId &&
				this.ID == test.ID &&
				this.ExternalId == test.ExternalId &&
				this.NINumber == test.NINumber &&
				this.LegalForename == test.LegalForename &&
				this.LegalSurname == test.LegalSurname &&
				this.Gender == test.Gender &&
				this.DOB == test.DOB &&
				this.EthnicityCategory == test.EthnicityCategory &&
				this.NOKFullname == test.NOKFullname &&
				this.NOKHome == test.NOKHome &&
				this.HouseNumber == test.HouseNumber &&
				this.StaffTelephoneNumber == test.StaffTelephoneNumber &&
				this.Initials == test.Initials &&
				this.Street == test.Street &&
				this.Town == test.Town &&
				this.Postcode == test.Postcode &&
				this.RequestedDate == test.RequestedDate &&
				this.ClearanceDate == test.ClearanceDate &&
				this.ClearanceLevel == test.ClearanceLevel &&
				this.ReferenceNumber == test.ReferenceNumber &&
				this.DocumentNumber == test.DocumentNumber &&
				this.AuthenticatedBy == test.AuthenticatedBy 
				return true;
			return false;

Which added 1/4h to the job. 


We need to take extreme care with personal data and so the idea of saving the old xml file to disk isn't acceptable unless it is suitably encrypted or securely within the TI's own system.

Alternatively, simply storing say an ID and a hash of the ToString() of the class instance and in clear (one is a string of comma separated numbers the other is a number) would offer a good approximation.

However the principles are sound and coding time here for TIs is relatively short.  Given that reporting covers most of the data and is effective for daily updates then it worth considering for appropriate integrations.

The example stores test data in clear on a machine which is contrary to GDPR if used with real data .  It is intended to offer concepts rather than a complete solution and appropriate alternative mechanisms are discussed in the text.