Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • suzyb 474 posts 932 karma points
    Mar 26, 2013 @ 17:51
    suzyb
    0

    Update key field before mass update

    Our client maintains an excel sheet of the courses they offer.  This spreadsheet gets updated as the year goes along and there is a course code to identify each course.  There is also a big update once or twice every year where courses are added / deleted as well as updated.

    We're looking into whether CMSImport will be able to import the spreadsheet into umbraco.  It looks like it will work for the normal update, each course will have a course code and the FieldAdapter and events seem to provide enough extensibility for what we need.

    However when the yearly / bi-yearly update happens the unique course code for each course is changed.  So for example this year a course could have code ABC13 but that would change to ABC14 next year. 

    We don't want to do a mass delete and create new records when these codes change so we have asked the client to include the old course code in the spreadsheet.  When this field is filled in we would like to find which node has this old course code as it's identifier and update it to the new one, then perform the import as usual.  Is this something we would be able to do with CMS import.

    Also does CMSImport delete records when the key is missing from the data source or would we still need to do so in the Imported event.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Mar 26, 2013 @ 20:47
    Richard Soeteman
    0

    Hi,

    This is possible but will require some coding, If you take a look at the ContentImport.RecordImporting event you can cancel an import. So what you could do in this event is either update the old record. then cancel the import to make sure the new record doesn't get imported. Or you can use this event to delete the old record and import this new record as new.

    The Items collection gives you all the fields from the record.  Using ContentRelation.GetRelatedDocument you can get the actual document based on the relation info. Below an example how to use the event to modify the document. It only requires a reference to the interface,businesslogic,cms and Umbraco dll's and the CMSImport.Extensions dll.


        public class SetUnpublish : ApplicationBase
        {
            public SetUnpublish()
            {
                ContentImport.RecordImporting += new ContentImport.RecordImportingEventHandler(ContentImport_RecordImporting);
            }

            void ContentImport_RecordImporting(object sender, RecordImportingEventArgs e)
            {
                //Add an extra day, you might check if teh value is null or not
                ((DateTime)e.Items["ClosingDate"]).AddDays(1);
            }
        }

     

    Is this something that you are after?

    Thanks,

    Richard

  • suzyb 474 posts 932 karma points
    Mar 27, 2013 @ 21:15
    suzyb
    0

    It looks like it might be. 

    Do you mean doing something like this.  Manually setting the values of the document and cancelling the actual import.

    void ContentImport_RecordImporting(object sender, RecordImportingEventArgs e)
    {
    Document d = ContentRelation.GetRelatedDocument(e.DataAdapter, e.DataKeyName, e.Items["Old Course Code"]);
    d.getProperty("courseCode").Value = e.Items["Course Code"];

    e.Cancel = true;
    }
  • suzyb 474 posts 932 karma points
    Apr 10, 2013 @ 12:54
    suzyb
    0

    This seems to be working however even though I am cancelling the import a new document is still being created, although no data is being filled into the properties.

    Is there something I need to set to stop this from happening.

Please Sign in or register to post replies

Write your reply to:

Draft