I have written the following code and setup a scheduled task to run every hour.
The process performs a SQL query on an external database application and if appropriate creates new nodes within the Umbraco site. The nodes are created and saved, but not published. All nodes created relate to calls logged by our Help Desk.
I have noticed that (on some occasions) multiple nodes are being created for the same call with each node having a number appended to the end, e.g. 00267239 (2), 00267239 (3), etc.
This doesn't seem to be occuring all the time and so wonder if it relates to :
Nodes being only saved and not published. As per my code below I am doing an "UpdateDocumentCache" after saving the new node.
The nodes created are being automatically moved into a year/month folder structure so wonder if this is causing the "confusion" within Umbraco
And here is my code (some parts omitted for brevity purposes).
using System; using System.Web; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Configuration; using System.Xml; using umbraco.cms.businesslogic.web; using umbraco.BusinessLogic;
namespace HeatDashboardDatabaseCalls { public class AddMajorIncidentReportNodes { public static void CreateNodes() { SqlConnection dataConnection = new SqlConnection(ConfigurationManager.AppSettings["HEAT-DB"].ToString());
The node will only get pushed into the documentcache when it is actually published, so yes that is your problem. To check if a document already exists use the document api (be aware that this is an expensive call as it goes to the database, so use it sparingly).
Hi Sebastiaan - thanks for confirming my suspicions.
In this particular case I think I will publish the node and alter the logic in my XSLT so as to not display the nodes until they are ready to be displayed - maybe add a true/false field to the document type.
ApplicationBase Event Creating Duplicate Nodes
Hi there
I have written the following code and setup a scheduled task to run every hour.
The process performs a SQL query on an external database application and if appropriate creates new nodes within the Umbraco site. The nodes are created and saved, but not published. All nodes created relate to calls logged by our Help Desk.
I have noticed that (on some occasions) multiple nodes are being created for the same call with each node having a number appended to the end, e.g. 00267239 (2), 00267239 (3), etc.
This doesn't seem to be occuring all the time and so wonder if it relates to :
And here is my code (some parts omitted for brevity purposes).
Can anyone shed any light / offer a suggestion as to where it is going wrong ?
Thanks in advance.
Nige
The node will only get pushed into the documentcache when it is actually published, so yes that is your problem. To check if a document already exists use the document api (be aware that this is an expensive call as it goes to the database, so use it sparingly).
Hi Sebastiaan - thanks for confirming my suspicions.
In this particular case I think I will publish the node and alter the logic in my XSLT so as to not display the nodes until they are ready to be displayed - maybe add a true/false field to the document type.
Thanks again
Nigel
is working on a reply...