Before I purchase a licence for this package I need to know whether or not it is possible within a scheduled import task to only import new records and not records that already exist within umbraco?
For example: I have a db table with a unique id (which I would store in a property within umbraco) from the external data source that I'd like to import once a hour say, but once a record has been imported I only want the scheduled task to import new records only. Is this possible within CMS Import? If so how?
You need to program a few lines of code for that. CMSImport comes with an event system. Before a record gets imported it will raise the RecordImporting event. When you cancel that event the record will not be imported. Below a snippet how CMSImport will find a relation between your datasource and nodes in Umbraco and cancel the event when a document is found. So only new records will be imported.In the result screen you will see skipped records after import. These are the records that you've canceled using the event.
publicclassCancelEvent :ApplicationBase
{
public CancelEvent()
{
// Wires up the event handlerContentImport.RecordImporting += newContentImport.RecordImportingEventHandler(ContentImport_RecordImporting);
}
privatevoid ContentImport_RecordImporting(object sender, RecordImportingEventArgs e)
{
//Cancel the importing event when a relation is found in the database
e.Cancel = ContentRelation.GetRelatedDocument(e.DataAdapter, e.DataKeyName, e.DataKeyValue) != null;
}
}
To use this snippet add references to the dll's
- umbraco
- cms
- businesslogic
- interfaces
- Cmsimport.Extensions
This example will only work in PRO because of the relation that is only available in the PRO edition.
Thanks for that, I've purchased a licence all ready to mess around with the events as you suggest and noticed that CMS import already seems to do the job of checking for existing records and skipping them already!
Scheduled import tasks
Hi,
Before I purchase a licence for this package I need to know whether or not it is possible within a scheduled import task to only import new records and not records that already exist within umbraco?
For example: I have a db table with a unique id (which I would store in a property within umbraco) from the external data source that I'd like to import once a hour say, but once a record has been imported I only want the scheduled task to import new records only. Is this possible within CMS Import? If so how?
Thanks,
Mike
Hi Mike,
You need to program a few lines of code for that. CMSImport comes with an event system. Before a record gets imported it will raise the RecordImporting event. When you cancel that event the record will not be imported. Below a snippet how CMSImport will find a relation between your datasource and nodes in Umbraco and cancel the event when a document is found. So only new records will be imported.In the result screen you will see skipped records after import. These are the records that you've canceled using the event.
To use this snippet add references to the dll's
- umbraco
- cms
- businesslogic
- interfaces
- Cmsimport.Extensions
This example will only work in PRO because of the relation that is only available in the PRO edition.
Hope this helps you, if not please let me know
Best,
Richard
Hi Rchard,
Thanks for that, I've purchased a licence all ready to mess around with the events as you suggest and noticed that CMS import already seems to do the job of checking for existing records and skipping them already!
Thanks,
Mike
Hi Mike,
Yes stupid me. you can skip records from UI indeed :-(
Thanks for the purchae by the way.
Best,
Richard
is working on a reply...