Scheduling a Culling Process to delete all records over 2 years old?

  • 8 September 2016
  • 5 replies
  • 1 view

Userlevel 3
Badge +16

Hi,

 

Hope you all doing well.

 

Can anyone advise if it's possible to create an automated K2 process to run everyday by itself to look in multiple Smartobjects and delete records older than 2 years old?

 

The various smartobjects all contain date fields, so is it possible to create a process to check the dates for each record in each smartobject and delete those records over 2 years old?

 

Thanks as always


5 replies

Badge +7

Hi ,

There is no such mechanism in k2 to schedule a process start automatically , it would be added in 4.7 release which is coming down the line in next 1-2 months ( not confirmed exactly) but you can do some kind of workaroud , create a timer job in sharepoint and add a list and on that start the workflow else you can do som power script to start the process else call K2 API to start process instance in window service and schedule it daily and you can add rest of the business logic in process to delete all the record which is having more than 2 years .

 

hope this will  help you .

 

cheers !!!

Arvind

Userlevel 3
Badge +16

Hi Avind,

 

I don't use Sharepoint.

 

Is there no way of Creating a Workflow that is running all the time and does a check (12am every 24 hours) for any records over 2 years old and delete them?

 

Thanks

Badge +10

It is possible to create a workflow that does polling every hour/day but its not recommended and can cause problems with the K2 Server if the workflow is kept running for an extended period of time since the state of that process instance keeps on getting larger and larger.

 

You could try this approach and schedule it using the Task Scheduler.  No SharePoint required.

http://help.k2.com/onlinehelp/k2blackpearl/devref/current/default.htm#using_the_windows_powershell_to_start_a_k2_process.html

 

Badge +7

It is possible to use the Windows scheduler to start a workflow we have done some testing but we dont have it in production yet.

 

You use a powershell script to call the workflow

 

here is a smaple script we used

[System.Console]::WriteLine(“ProcessName“)

Add-Type -AssemblyName (‘SourceCode.Workflow.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=16a2c5aaaa1b130d’)

$conn = New-Object -TypeName SourceCode.Workflow.Client.Connection

$conn.Open(“ftwk2d001“)

$pi = $conn.CreateProcessInstance(“ENT-E-Gates ProcessGate1A“)

$conn.StartProcessInstance($pi)

$conn.Close

 

Save this in a file like script.ps1 then use the windows scheduler. Set the start program as powershell and the argument to the full path like c:script.ps1

 

You do have to have powershell enabled and the correct permissions.

 

let me know if this helps I can probably find some more information.

Userlevel 3
Badge +16

Hi Micki,

 

Sounds interesting, can you provide more information as i don't understand the script you posted.

 

As a workaround, i managed to create a sql query and scheduled that in Windows to delete records over 2 years, which seems to work ok.

 

Is there any issues with using SQL queries to delete records from a K2 Smartobject? Would it mess up an K2 smartobject functionality?

Reply