Synchronizing page details to some third-party service once the page is published with "publish from

Mirko Milanovic asked on September 1, 2021 10:51

How can I synchronize page details to some third-party service once the page is actually published with "publish from" (when it reaches its "publish from" date and time), because there is no event for that?

Correct Answer

Dmitry Bastron answered on September 3, 2021 08:59

Hi Mirko,

I'd agree with Juraj, a custom scheduled task will be the right approach here. Please consider the following logic:

  • To support incremental import, your scheduled task would require storing the history of executions. In particular, date-time of task run, status (successful or not), maybe textual log of the execution.
  • To store the history of task executions it's better to use Module Custom Classes. Basically, create a Custom Class holding TaskStartDate, SuccessfullFlag, TaskTextLog.
  • In task code you can do the following:
    • In task execution history find the most recent successful task run, and remember it's TaskStartDate - in the current task run you'd need to find all pages that have become published since that date and time.
    • Query the database to find these pages (query example below)
    • Execute export to third-party system.
    • Save the current task run time, successful flag and log as your Custom Class instance, so that on the next run of the scheduled task the date you need to query your pages will shift.

Here is the query example:

var docsToExport = DocumentHelper.GetDocuments()
    // only published document will be retrieved
    .Published()
    // exclude unpublished changes if you use workflow
    .LatestVersion(false)
    // Simple pages created without versioning or workflow
    .WhereGreaterThan(nameof(TreeNode.DocumentModifiedWhen), lastSuccessfullRunTime)
    .And()
    .WhereNull(nameof(TreeNode.DocumentPublishFrom))
    .Or()
    // Pages created with versioning enabled 
    .WhereGreaterThan(nameof(TreeNode.DocumentPublishFrom), lastSuccessfullRunTime)
    .And()
    .WhereLessThan(nameof(TreeNode.DocumentPublishFrom), currentTaskStartTime)
    .ToList();

For pages under workflow this query may become more complicated.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on September 1, 2021 14:48

I would create a scheduled task which will be checking the pages for the date field and once the condition is met, you will invoke the sync.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.