Setting ModerationInformation.Status from Approved back to pending removes - sharepoint

Seeing if anyone else has had this problem and a resolution to it.
I have a visual studio sequential workflow on a list (not a library) which does NOT use tasks, the approval process is done through the Approve/Reject OOTB buttons on the list item. The approval is a 2 stage approval, whereby if the 1st stage is completed (via clicking the Approve OOTB button), i reset the ModerationInformation.Status from Approved back to pending then send an email to the 2nd stage approver.
My problem is, when i set the the ModerationInformation.Status back to Pending from Approved so there is never an approved version, the Creator loses permissions to view the item, and i get the "cannot find item" error from SharePoint for the person who created the item. The 1st and 2nd level approvers and anyone with approve rights CAN still see the item.
Some more background information. the code i am using to update the moderationinformation is
I get the properties from the workflow event and get a hook into the listitem
properties.Item.ModerationInformation.Status = SPModerationStatusType.Pending;
properties.Item.Update();
can anyone help.

Try using properties.Item.SystemUpdate(); this prevents SHarePoint from triggering any attached EventReceivers etc. I've had the same thing happen also. IMHO this is related to the fact that the item goes into update mode, then SharePoint basically has taken control over the item (seeing as workflows are usually run as the System account) but still sends you back to the the return url (i.e. the EditItem page of the list).
Since SharePoint is probably still doing work on the item (and when you use item.Update() it goes through all events etc. etc.) you cannot open it anymore, because you are not the system account.
When SharePoint finishes (after sent the emails etc.) the item is accessible by users again.
Like I said, I had the same thing happen during long running (i.e. longer than 2 to 3 seconds) EventReceivers / Workflows.

Related

SharePoint Designer 2013 Workflow Lookup for SP Online

I'm having issues with my SP Online Workflow. Setting up a custom list for Time-off requests. Person puts in request, task is assigned to their manager, then manager either approves or denies request, then informs the requester of the outcome. That whole part works great.
I've added an option for the requester to cancel the request. If the request has already been approved by the manager then it sends an email to the Manager, HR, & requester saying the request was cancelled. This part works fine.
The part that I'm having issues with is if the request hasn't been approved/rejected by manager and requester cancels. It's not sending out the email to manager and changing the Workflow Status.
I have it configured exactly like the cancel workflow if it's been approved. What am I missing here? Any help would be greatly appreciated.
Here are some images of the entire workflow and the Workflow lookup in question:
Entire Workflow
Workflow Lookup in Question
Thanks
I think if one of your condition complete, it should just go the next stage in your case which is end of workflow. When you condition is satisfied, you don't need to go through all other if anymore.
If request cancel equal no
If outcome equal approved
Go to next stage
If outcome equal rejected
Go to next stage
Else
If taskStatus equal not started
Go to next stage
If taskStatus equal completed
Go to next stage
I switched not started and completed. Because logically speaking you should go not started first.

Workflow logic for multiple-approval process

I have the need to create a workflow that will begin when a user submits an infopath form to a document library. Some fields will be extracted from this form to build the workflow.
Steps:
Notify the form submitter's manager and request that they approve or disapprove.
One or more other users will be notified and requested to approve or disapprove the submitted form. If any of them reject the form, the original requester should be notified and requested to re-submit the form.
I can make a workflow for step 1 and then check the value of that field in the task to see if it's either approved or disapproved before moving onto the next step or not.
The issue I'm having is how to check whether someone has rejected or approved in the 2nd step, since there could be multiple users.
Any help is greatly appreciated
After step 1, you can track the workflow in the "workflow Tasks" list, i.e., you can get who rejected it, when they did it and why they did it(if you have a notes/reason column).
If you/your company can afford to buy a third party tool like nintex/bamboo workflow conductor/k2, this approval process come out of the box. They are a bit expensive though

SharePoint Expiration Policy does not fire ItemDeleting Event Receiver

We have attached an ItemDeleting event receiver to a list that requires certain maintenance to be performed in other lists whenever an item is deleted. It works fine when an item is manually deleted by a user. However, if an item is deleted as a result of the Information Management Policy we have defined to delete expired items, the ItemDeleting handler is not executing. Is this standard MOSS behavior? If so, are there any suggested workarounds?
I would run a custom workflow using the policy, there you can define your own logic, which is what you probably try to achieve

Built in Approval workflow not started on item edit event

I have requirement where when a user enter new item in a list first approver approves it then publisher approves it. Once publisher approves it the text will be visible to all.
I have used SharePoint built in Approval for that where I have set my workflow to start when new item created and item is changed.
When I Add new item workflow triggers and process of approving the item works fine and update the workflow status as completed.
But when I edit the same item, Workflow on item changed is not fired.
Can any one tell me how to set SharePoint built in workflow to start on new item created as well as item change events.
FYI: I have set content approval to "No" in my versioning settings.
After lots of investigation I found that I have selected checkBox for "After the workflow is completed: Update the approval status (use this workflow to control content approval)".
Here I have not selected require content to be approved option for my list and for the same list I was updating approval status once workflow get completed.
What I observed is deselecting this option my workflow get fired successfully on new item created and Item change events.
To make the checkbox work for you, you need to setup content approval enabled on the library level. If not, it is going to fail with an error in the backgound.

How do I trigger a Sharepoint Workflow from code?

I have a workflow that is triggered by the creation of a list item and sends out an email when the list item is created.
If I create a new item in that list through the Sharepoint front end it sends the email.
I have a small console application designed to set the list item through the Sharepoint API. This is run as a scheduled task on a daily basis ( the purpose of the list is to nominate someone for a daily rota ) in the middle of the night. The scheduled task is run with the credentials of the Site Collection Administrator for the site.
The list item is added but the workflow is not triggered. In the log I get the following message:
Declarative workflows cannot automatically start if the triggering action was performed by System Account. Canceling workflow auto-start.
It appears as though the list item is being added by the system account rather than the user who is running the code. What do I need to do in order to have my code interact with Sharepoint using the same identity that is running the application?
Consider explicitly impersonating one of your SharePoint users (in this case the site collection administrator.) I answered a similar question over here: UpdateListItem method and System Account
Once you've created a SPSite object using the context of the impersonated user all operations against that object and its children will be performed as that user.
It might be better to set your second workflow to being manually started, and then start it programmatically (which your System Account -can- do):
There's probably a better way to do this, but this has been working for me:
// Look through all potential workflows for the correct one:
foreach (Microsoft.SharePoint.Workflow.SPWorkflowAssociation flowAssoc in SPContext.Current.Web.Lists["YourListName"].WorkflowAssociations) {
if (flowAssoc.Enabled && flowAssoc.AllowManual && (flowAssoc.Name.Trim() == workflowNameToLookFor.Trim())) {
// Start the workflow on the current item:
SPContext.Current.Site.WorkflowManager.StartWorkflow(SPContext.Current.Web.Lists["YourListName"].Items[itemIndex], flowAssoc, flowAssoc.AssociationData, true);
}
}

Resources