© 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 - Applicant Update Code Walk Through

Please see our advice on importing applicants via ATF or AIF before considering coding.

This example is intended to show the principles of updating an existing applicant in SIMS based on data from an external system.  The data is provided to the code via an AIF import file which may contain one or more applicants to update.  It does not include the creation of an applicant.

        public void ProcessUpdate(XmlDocument AIF)
        {
            // Firstly we need to load  the applications from the AIF file
            foreach (XmlNode n in AIF.SelectNodes("ApplicationImport/ApplicationCollection/Application"))
            {
                Applicant a = new Applicant(n);
                if (a.ApplicationReferenceNumber != "")
                {
                    if (!MyApplicants.ContainsKey(a.ApplicationReferenceNumber))
                    {
                        MyApplicants.Add(a.ApplicationReferenceNumber, a);
                    }
                }
            }
            

The Idea of the code is that we pass in an AIF file and extract all of the applicant updates in to a dictionary of applicants keyed by application reference number (ARN).  Whilst technically the ARN is optional, it would be sensible for 2 systems exchanging data to mandate a unique value for ARN set by the providing admissions system.

    public class Applicant
    {
        public int ApplicantId { get; set; }
        public string Surname { get; set; }
        public string Forename { get; set; }
        public string Title { get; set; }
        public string ApplicationReferenceNumber { get; set; }
        /// <summary>
        /// Load from AID
        /// </summary>
        /// <param name="n"></param>
        public Applicant(XmlNode n)
        {
            // Won't know applicant id when loaded from AIF
            XmlNode n2 = n.SelectSingleNode("BasicDetails");
            if (n2["ARN"] != null)
            {
                ApplicationReferenceNumber = n2["ARN"].InnerXml;
            }
            else
            {
                ApplicationReferenceNumber = "";
            }
            Surname = n.SelectSingleNode("Surname").InnerXml;
            Forename = n.SelectSingleNode("Forename").InnerXml;
            Title = n.SelectSingleNode("Title").InnerXml;
        }
   }

The applicant class is a start and needs to be extended to cover all of the data that you wish to import.

The code then goes on to iterate once through all of the applicants on file and check to see whether an update has been provided.  If it has, it applies the update, validates and saves; if not it skips on to the next applicant.  Unfortunately you need to load the details of an application before you can obtain the ARN to compare, hence this is probably the most efficient model; You could of course exit as soon as all of the applicants in the file have been consumed.

// More efficient to process the xml and load it rather than iterate through SIMS 
            // many times
            SIMS.Processes.Admissions.ApplicationBrowser apb = new SIMS.Processes.Admissions.ApplicationBrowser();
            apb.PopulateLookups(true);
            apb.Search("%", "%", -1, -1, -1);  // Load all applicants
            foreach (SIMS.Entities.Admissions.Application apn in apb.Applications)
            {
                SIMS.Processes.Admissions.MaintainApplication app = new SIMS.Processes.Admissions.MaintainApplication();
                bool maintApp = app.RetrieveApplication(apn.ID);
                ApplicationReferenceNumber = app.DetailedApplication.ApplicationReferenceNumber;
                Applicant a = null;
                if (MyApplicants.TryGetValue(ApplicationReferenceNumber, out a))
                {
                    app.DetailedApplication.Applicant.Surname = a.Surname;
                    app.DetailedApplication.Applicant.Forename = a.Forename;
                    // ...
                    if (app.Valid())
                    {
                        System.Data.DataTable dt = null;
                        app.Save(true,out dt);
                        if (dt!=null && dt.Rows != null && dt.Rows.Count == 0)
                        {// Presumably happy  }
                    }
                }
                else   {// No update in this file for this applicant    }
            }