If your customer tells you that you can only deploy the sandboxed solution on the server, you cannot deploy any custom code on the server. Then the customer tells you that they also need to perform some automated checks on the server on a regular basis, which is a required requirement. At this time, you will be hard. Due to the limitations of sandboxed, you cannot register a timer job (timer job) that can be periodically run on the server. However, the customer's requirements require that you be able to perform certain operations on the server on a regular basis, well, is there any way to achieve this goal?
In a Sharepoint website, there is something that can be automatically executed on a regular basis. This is the Information Management Policy function built in Sharepoint. The Information Management Policy allows you to specify an expiration Policy for a list of data, and then when the list item arrives at a certain time point (for example, one week after the list item is created ), execute a specific operation (for example, starting a custom workflow ).
Next, I will demonstrate how to use the information management policy in a Sharepoint website to perform a custom operation on a regular basis. First, create a secondary list on the website, such as the scheduled job secondary list. Open the list settings and click "Information Management Policy Settings ".
Select set policy for "project" content type, and then the policy setting page is displayed. On the page, select "enable retention" and click "add retention phase ".
In the displayed dialog box, set the time when the policy is activated. For example, after the creation date is one day, the policy is automatically activated one day after a list item is added. Select "Start Workflow" in the Operation drop-down box, so that you can select a custom workflow created by Sharepoint designer. The "Activate scheduled job" Process on is a workflow that I created in SharePoint designer. In the periodic area below, you can choose to have the retention policy be executed repeatedly according to the specified period. In this way, the custom workflow is automatically executed every day.
However, the SharePoint designer workflow cannot be customized code! To do this, you can create a second secondary list on the website, for example, the "scheduled job activation list", and then put only one operation in the periodically executed workflow: create a list item in the scheduled job activation list.
Then, you can bind an event handler to the scheduled job activation list in sandboxed solution. In the end, as long as you add a list item to the first secondary list and the "scheduled job secondary List" (you only need to manually add a list item at the beginning ), follow the steps below to activate an event that is automatically executed on a daily basis:
(1) manually add a list item to the "scheduled job auxiliary list"-> (2) after one day, the Information Management Policy's retention policy is activated-> (3) after the retention policy is activated, start our custom workflow-> (4) Add a list item to the scheduled job activation list-> (5) the event handler bound to the "custom job activation list" is activated, and the code we wrote in the event handler is executed-> (6) one day later, the Information Management Policy's retention policy will be re-activated again, back to step (3)
Of course, this method is also limited. The first limitation is that the shortest timing cycle of the retention policy is one day and cannot be shorter than one day. Second, the retention policy is actually scheduled by a system timer job, the execution time of this system timer job does not necessarily match our needs (but if you have the server farm management permission, you can modify the running cycle of this timer job ). Finally, because the code is stored in the event handler and runs in the sandbox, you cannot perform an operation that takes a long time to complete.