SharePoint 2013. I'm using VS to create document sets in SharePoint. When they're created, I'd like to use a workflow to auto-fill a few columns. However, the workflow won't kick off unless I create doc sets via the GUI. I confirmed that the "Created By" user is my user and NOT System Account whenever I use VS.
I ran this followed by an iisreset. Did not work.
stsadm.exe -o setproperty -propertyname declarativeworkflowautostartonemailenabled -propertyvalue yes
I also ran the following script, which essentially does the same thing.
$spWebService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$spWebService.DeclarativeWorkflowAutoStartOnEmailEnabled = $true
$spWebService.Update()
Didn't work.
I know these scripts worked because workflows now auto start whenever I email a list (woo!).
I have two workflows attached to this library. One kicks off ONLY on item change, and the other (my problem child) is supposed to kick off when an item is created or changed.
I also created a test VS script that edits items in the library, but the workflows still don't kick off. Which makes me believe it's a System Account issue. Even though the "Modified By" account shows my username.
Any advice is appreciated. Thanks in advance!
Edit: I should note, I cannot activate the "Workflow can use app permissions" site feature for some reason. I run into errors and haven't gotten around to resolving it.
Also, here is my code:
using System;
using System.Web;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.BusinessData;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.BusinessData.Runtime;
using Microsoft.BusinessData.MetadataModel.Collections;
using System.Xml;
namespace CRM_Data_Column
{
class Program
{
static void Main(string[] args)
{
string siteURL = "http://spsite/";
using (SPSite siteCollection = new SPSite("http://spsite/"))
{
using (SPWeb web = siteCollection.OpenWeb("subsite"))
{
OpenUserContext(web, siteURL, "DOMAIN/username");
}
}
}
private static void OpenUserContext(SPWeb web, string siteURL, string user)
{
SPUserToken userToken = web.AllUsers[user].UserToken;
SPSite impSite = new SPSite(siteURL, userToken);
SPWeb impWeb = impSite.OpenWeb("subsite");
//do things as impersonated user
}
}
}
Edit #2:
I figured out that it doesn't work when I create only one item, but sort of works when I create 3 or more.
When I create a bunch of items, the workflow kicks off for all except the last item. Also, the workflow for the second to last item gets stuck on "In Progress". Am I not updating items correctly?