3

This question already has an answer here:

I am creating a workflow that sends an email to internal & external users. Since, in sharepoint Online, workflows are not allowed to send emails to external users. It is not the case in "workflow 2010", so I created a "workflow 2010" and attached it to the site collection through "Sharepoint Designer 2013".

Here is my workflow "SendEmail"

Now here is my SendEmail workflow, is there a way I could start this workflow from my Sharepoint Addin (Office 365) i.e JavaScript solution

Thanks

marked as duplicate by Robert Lindgren, Mohamed El-Qassas MVP Jul 20 '17 at 13:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Please refer to my answer in similar :thread: – DvG Jul 20 '17 at 12:43
2

JSOM

Start SharePoint Workflows with JavaScript Client Object Model

function LoadScripts(){
    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", StartSiteWorkflow);
    })    
}

function StartSiteWorkflow(){

    var context = SP.ClientContext.get_current();

    var web = context.get_web();

    //Workflow Services Manager
    var wfServicesManager = new SP.WorkflowServices.WorkflowServicesManager(context, web);

    //Workflow Interop Service used to interact with SharePoint 2010 Engine Workflows
    var interopService = wfServicesManager.getWorkflowInteropService()

    //Initiation Parameters have to be in a plain JS Object.
    var initiationParameters = {
        FirstName: "Vardhaman",
        LastName: "Deshpande"
    };

    //Start the Site Workflow by Passing the name of the Workflow and the initiation Parameters.
    interopService.startWorkflow("My Workflow", null, null, null, initiationParameters);

    context.executeQueryAsync(function () {
        console.log("workflow started");
    },
    function (sender, args) {
        console.log(args.get_message());
    });
}

jQuery(document).ready(function () {
    LoadScripts();
});

C#

Follow my paste bin

  • Just a note: this solution won't work for any SharePoint 2010 workflows using assignment stages parameters. – Charles Grunwald Jul 17 '16 at 4:23
  • Is it possible to update the Assign To field that is in Approval/Collect Feedback Workflows with this solution? I tried to assign a person by setting AssignedToId to the id of the person I wanted to assign the workflow task to in the initiationParameters but the workflow was kicked off without being assigned to anyone. – James11 Aug 3 '16 at 19:52
  • I have not try that yet but I believe there should be a way. @James11 – Atish Dipongkor - MVP Aug 4 '16 at 4:40
  • I agree, it seems like my problem is I can't figure out how to get the workflow to recognize a Person/Group initiation Parameter. If I try to use the persons name or email it just recognizes it as a string, and if I try to use the Id it just recognizes it as a number. Trying to set the Reviewer or Approver as a SP.Data.UserInfoItem object doesn't work either, in that case the parameter appears to get completely removed from the XML request that is generated for SharePoint. – James11 Aug 4 '16 at 14:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.