I am starting a Sharepoint 2013 Workflow via javascript and I want to set one initiation parameter as a person in it.
Here I define my initiation Parameter and start the Workflow. I am using a people picker for the person field. I tried different notations for the person like id, mail, display name, key and json objects.
var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;
var keys = peoplePicker.GetAllUserKeys();
var initiationParams = {};
initiationParams["Person"] = keys;
initiationParams["String"] = "test";
startWorkflow("name", initiationParams);
With this function initiation Parameter can be send when starting a workflow. It works with string parameter. I got the code from the last anwser of: https://sharepoint.stackexchange.com/questions/175041/trying-to-start-sharepoint-workflow-from-code
/**
* Starts a SharePoint 2013 Workflow on a particular list or library item.
* https://sharepoint.stackexchange.com/questions/175041/trying-to-start-sharepoint-workflow-from-code
*
* @param {string} workflowName The name of the Workflow
* @param {string} initiationParams The initiation Parameters of the Workflow
*/
function startWorkflow(workflowName, initiationParams) {
var itemId = 1;
var listGUID = "{643fa273-936b-4a21-a602-0589ccafa1b0}";
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () {
SP.SOD.registerSod('sp.workflowservices.js', SP.Utilities.Utility.getLayoutsPageUrl(
'sp.workflowservices.js'));
SP.SOD.executeFunc('sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager",
function () {
var ctx = new SP.ClientContext.get_current(),
wfsManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx
.get_web()),
wfSubs = wfsManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList(
listGUID);
ctx.load(wfSubs);
ctx.executeQueryAsync(function () {
wfsEnum = wfSubs.getEnumerator();
while (wfsEnum.moveNext()) {
var wfSub = wfsEnum.get_current();
if (wfSub.get_name() === workflowName) {
wfsManager.getWorkflowInstanceService().startWorkflowOnListItem(
wfSub, itemId, initiationParams);
ctx.executeQueryAsync(
function (sender, args) {
console.log("Successfully started workflow.");
},
function (sender, args) {
$("#workflowResult").html(
"Fehler beim Starten des Workflows.");
console.log("Failed to start the workflow.");
}
);
}
}
}, function (e) {
console.error(e)
});
}
);
});
}
How do I send a person via initiation parameters to my workflow via javascript?
One option you may consider is to pass the SharePoint user ID (UID) as an integer parameter or the email address as a string parameter and then resole it to a person within the first stage of the workflow.