How to terminate paused workflow from another workflow? - sharepoint

we have a requirement to delete items from a SP list if they were not modified for 15 minutes.
I configured a simple workflow in SP Designer and assigned it to a change action that pauses for 15 minutes and then deletes the item.
Now, if the item changed while the original workflow is paused, a new workflow will be started (I presume) with a new counter.
But how to terminate the original workflow so that it wouldn't delete the item earlier?
We are on SP2013 on Office365.
Thanks,

I think you can solve it other way.
Use SP 2013 workflow platform, and set the trigger to item creation.
create a date/time variable and set to current date or modified field value
pause wf for 15 minutes
if currentItem:Modified less then or equal your variable stored time
if yes: delete item
in transition to stage section use the 3. step again and if yes: select end the workflow, if no: go to stage one

Only way I can think of is to make the workflow run a Powershell script that has the rights to stop workflows. But keeping track of the workflow instance id and the item is going to be a hazzle.
How about simply putting a check at the end of the workflow that checks if the last modified field is older than 15 minutes. If it is older then delete the item, if it is not then terminate that workflow without action.

Related

Add fields to Sharepoint Workflow Task

I'm currently making a pretty simple approval workflow in sharepoint using sharepoint designer. One of the design goals that we have for this workflow is that we want to minimize the amount of custom coding that we have to do so I'd appreciate answers that involve using sharepoint designer instead of whipping out VS.
So the workflow should start when a person adds an item to a list.
When the workflow kicks off it would create a task and and assign a due date of +2 business days and assign the responsibility to a group of users
When a user completes the task then it would record the individual person who completed the task as well as the date it was completed.
It's pretty easy to add fields to the list but the purist in me kind of balks at this since these fields would be null and it violates first normal form. Ie a list that went to Task1 but not Task2 would have four fields Task1ApprovedBy, Task1FinishedDate, Task2ApprovedBy, Task2FinishedDate and both the Task2 fields would be null.
--edit--
Sorry If I'm not being clear about the question. I'm using Sharepoint Designer and I would like to update a list item in a lookup when a user completes a task item. How do I select the last task for a particular item that was completed and update that last task two values "Completed By" and Completed Date values? I'd prefer to do this on the Task list since that would also make reporting easier. I'd just create a view on the Task list instead of doing some type of join between the two list to when a particular task was completed.
Thank you for the help!
Jason
It sounds like you need two workflows here. One on the "Main" list and one on the "Tasks" list:
The first workflow is tied to the "Main" list. It fires when a user creates a new list item in the "Main" list. This workflow simply creates a new item in the "Tasks" list (with the correct people assigned, description, dates, etc...)
The second workflow is tied to the "Tasks" list. It fires whenever an item in the Tasks list is changed. The workflow checks to see if the status field is "Complete". If it is, then assign the "Completed By" field to the current person editing the task and assign the "Completed Date" value to today.
(Note that, in a SharePoint Designer workflow, there is no way to evaluate the properties of the list item prior to the update. If a completed task is updated, the SPD workflow will be unable to determine that the task was already completed. Basically, each update to a completed task will update the Completed By/Date fields. If you want a more complex workflow - which only updates when the status is changed to "Complete" - you will need to use Visual Studio).

Automatically copy list data from one list to another list after 1 month

I have list that having data stores dynamically once the infopath form has been submitted. I want to archive this data after 30 days of creation date of any data. can you please suggest how would i do this. see i can do this by workflow but how can i set the condition that once 30 days complete after creation of any list it will automatically copy into other list.
First I would want to question WHY you want to move it to another list?
Why not simply setup a view on your main list showing only records created in last 30 days :-
Created >= [Today]-30
(And yes, you can use Today in view filters)
The best way to proceed is to create a timer job and define the criteria (like when should it be running) while creating the job. We have a very helpful post by SharePoint MVP here on how to create custom jobs. Note, you can test the job and business logic for shorter duration and if it works fine, you can simply extend the job duration for 30 days.
Its very simple, all you have to do is to define your 'copying list' logic in the Execute method of job class.
Good luck
I believe you can simply use standard out-of-the-box workflow activities to do this - no need for timer jobs or console apps.
Using SharePoint Designer, create a new workflow (New -> SP Content -> Workflow). Specify the list to attach the workflow to.
Specify that the workflow should start on item creation only.
In the first Step, add an action: Pause for duration. Make the duration 30 days.
Add another action: Copy list item. Specify the list to copy to.
Optionally: create a third action: Delete list item if you want the original item to be deleted from the original list.
And I think that's it :)
you have to crate a timer job which runs daily and move the items which are one month old
Potentially the easiest solution is to create a console application that you schedule to run on the SharePoint server (an alternative to creating a timer job).
Depending on how you want to archive the data, you could:
Get the list items (probably using GetItems), save them to a file or a DB, and delete the old items
Use custom STSADM commands to export the list (backup just the list)
Backup the entire site using STSADM
There's a limit on number of items in a list of 5000 items and if you change this in administration you'll kill performance. There are perfectly valid reasons to want to archive old items off of a rapidly growing list. exceeds the list view threshold 5000 items in Sharepoint 2010

sharepoint 2007 workflow trigger

I have an initial workflow in Sharepoint Designer that triggers whenever an item is created and also whenever an item has changed in the 'Employee' list .
Within second workflow I am updating the 'Employee' list and the workflow above is triggered.
Is there any way I can check in the intial workflow if the item has been updated by a user or if it was updated by a workflow. In the case if the item was updated by a workflow I would not want to trgigger it.
Many Thanks,
Through SharePoint Designer, you cannot cause an update to an item to not trigger workflows that are listening for it. But, you can cause the workflow to basically be skipped with one extra Step.
Try checking out this article at Microsoft Office, which discusses secondary workflow interactions in SharePoint Designer. In the first step, it identifies whether an item was created by a specific workflow, and cancels the workflow if it isn't. We just need to adapt this - if we successfully identify the item as being modified by your secondary workflow, then we want to cut off the first workflow.
You need to create a new Step in your initial workflow, and move it to the top. In it, choose the Compare Tasks Condition. In that condition, set field to be "Workflow Name", leave the operation as "equals", and set value to be the name of your secondary workflow. Then, add a Stop Workflow Action, specifying some appropriate workflow history message to indicate that the workflow was triggered by the secondary workflow so it was terminated.

need to put a delay of about 5 seconds between two actions of sharepoint designer workflow

( sharepoint 2007 )
i am creating a sharepoint workflow
this workflow is started when an item is created or changed in the list called ListA
this item has a field called user assigned
when the item is created this field is empty
the first step in the workflow is - grant item permission
in this step the creator of the item is granted contribute permission
the second step is to update field user assigned with the value created by of current item.
when the item is created its contribute permission are not with the user who is logged in . Thats why we use the firt step to give the user logged in the contribute permission. and after the first step has got executed . the contribute permissions are given to the user logged in and now he should be able to updated the user assign field as the next step of the workflow.
However the problem is that even before the first step of granting permissions has completed. the second step is executed and since the user logged at that time still doesn't have contribute permissions the workflow stops without updating user assigned field. if i could somehow produce a delay of about 5 seconds between the first and second step of the workflow my problem would be solved.
but I believe in sharepoint designer workflow the minimum pause is of 1 minute , which is much more than i require.
what should i do ?
Try to update SPListItem object by calling SPListItem.Update() and see if it helps.
If not, then just answer to your question: execute System.Threading.Thread.CurrentThread.Sleep()
And putting in a delay activity will serialize your workflow into database and only timer job will wake it up (which usally runs no more often than each 5 minutes, even if your activity delay is set to 1 minute).
in sharepoint designer workflow there is an option for set time portion of date/time
set time as 00:o5 for your date field(out put to one variable-userdefined variable name)
then pause until sources is workflow data field is your varaible name.--ok--> finish the workflow
Add a code item and use System.Threading.Thread.Sleep(5000);

Block SharePoint workflow from running unless prerequisites are met

I've got a scenario where I want a workflow to not run if a certain condition is true, otherwise to run when a list item is created. The scenario is for a people management system. If a new list item (staff member) is added to the list then the workflows job is to go between the various departments and get everthing setup. Eg payroll, IT account ect. One of the fields is Start Date that may or may not be entered. If it is entered then I don't want the workflow to run when the item is created. I want the policy on the list to start the workflow on that date. I can add some code into the workflow to end itself if the date is in the future but then this will show as completed on the list. This is a problem because the workflow shouldn't show that it's run as in effect it's waiting for the date to be correct.
In other words, is there something in onWorkflowActivated that allows me to stop the workflow from triggering so that nothing shows up in the site, in essence to suppress the workflow from running as if it was never triggered by the OnCreated event.
Can you add a new step at the beginning of the workflow to fill in the Start Date? I think this makes sense in terms of your workflow because the HR person has an action item on their plate: enter the start date.
Otherwise you could make Start Date a required field on the sharepoint list.
This is SharePoint Designer version, see if you can use the same activities in VS
Create a second workflow that executes the rules after StartDate is set
In the main workflow, create a step with the action 'Wait for Field Change in Current Item' and config it to 'StartDate not Empty'.
The next action will be a 'Start Workflow', executing the second Workflow you created.
You also have a Stop Workflow activity

Resources