Start a Nintex Workflow Cloud workflow from the Sharepoint ECB menu

ECB Menu in Sharepoint List or Document Library allows one to manually trigger an action, and this could be an action to start a workflow from Nintex Workflow Cloud. We would love to have the option to manually trigger a workflow to start.

Here is the story line, looking at a document library in Sharepoint, based on the use case we discussed in my previous blog post, a Marketing Coordinator uploads the Excel Attendant List to a Sharepoint folder in Marketing Site’s Document Library, in this case, not all the documents in the library are leads to be generated in Salesforce, only this particular excel file is, and we want to manually trigger a Nintex Workflow Cloud workflow to help collect and upload leads from this file to SalesForce. To do that, we can simply add a custom ECB Menu to the Document Library (i.e. same applies to Custom List in Sharepoint). Diagram below illustrates what you will get: 

Starts Nintex Workflow Cloud from Sharepoint ECB Menu

Before we get into how to add the ECB menu in Sharepoint Document Library, let us take a look at how to start a workflow in Nintex Workflow Cloud. We going to use the “Public web form” Start event option in this exercise, the configuration of a sample workflow Start Event is shown in the diagram below:

This configuration will give us a web form URL with the format of https://{your-tenant}{workflow-id}. Using Fiddler to trace the form submission, you will find the form is being submitted with the following HTTP POST request.

POST https://{your-tenant}{workflow-id} HTTP/1.1

Host: {your-tenant}

Connection: keep-alive

Content-Length: 165

Accept: application/json, text/plain, */*

Origin: https://{your-tenant}



Content-Type: application/json;charset=UTF-8




With the HTTP POST request details we learned, we will be able to include a HTTP POST request in our ECB menu action. Again, there are different ways to achieve that – Sharepoint-Hosted Add-ins, Provider-Hosted Add-ins, and simply the way we going to get that without the need to create an add-in using Visual Studio is the Display Template client side JavaScript.

1. Edit the Document Library page by selecting the Edit Page from the page menu as shown.

2. Insert a Content Editor web part to the page, 

3. With the cursor in the Content Editor’s content area, click Edit Source to edit the source of the content

4. Here is the JavaScript code to be included in the Content Editor’s source

<script language="”javascript”" type="text/javascript">

function Custom_AddDocLibMenuItems(m, ctx)
  var strDisplayText = 'Upload to SalesForce';
  var strImagePath = '';
  var strAction = 'send2NWC()';
  // Add our new menu item
  CAMOpt(m, strDisplayText, strAction, strImagePath);

  // add a separator to the menu

  // false means that the standard menu items should also be rendered
  return false;

function CAMOpt(p,wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc)
     var mo=CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc);
     if(!mo)return null;
     if(wzText != "Delete Item") AChld(p,mo);
     return mo;

function send2NWC()
    var url = "https://{your-tenant}{workflow-id}";
    var method = "POST";
    //depending on the value you passing to the workflow, I am using selected item's Url here
    var postData = '{"se_file_name1":"' + currentItemFileUrl + '"}';
    var async = true;

    var request = new XMLHttpRequest();

    request.onload = function () {

          var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
          var data = request.responseText; // Returned data, e.g., an HTML document.
     }, url, async);

     request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");

     // Sends the request to the server.
     alert('Leads uploaded');

Tip: Few quick references getting values from Sharepoint Display Template:

currentItemFileUrl (i.e. selected item’s URL)

currentItemID (i.e. selected item’s ID in the list)

_spPageContextInfo.listId (i.e. List Id)

_spPageContextInfo.siteId (i.e. Site ID)

ctx.listName (i.e. List ID)

ctx.ListData.Row[currentItemID-1].UniqueId (i.e. selected item’s GUID)

ctx.ListData.Row[currentItemID-1].{column name} (i.e. list column value)

From Excel to SalesForce in Nintex Workflow Cloud

It’s easy we get into perception that a workflow always start from a form submission, and we’ve been telling the story of that. But in reality it’s not always the case, take Attendance List for instance, event coordinator taking attendance list with Excel at the reception of the event, is something very common and practical. the Attendance List will then be used to create Leads in CRM system for Account Management to follow up. This is just the right scenario we could easily automate in Nintex Workflow Cloud platform, I am going to share how the scenario could be automated in Workflow Cloud, the attendance of an event was taken using the Excel spreadsheet, and saved in OneDrive to trigger a workflow reading the attendance list to create leads in SalesForce.

Instead of explaining every single workflow action, I am just going to explain the key actions used to achieve our objectives here. Later part of this writing, I will share the pictorial flowchart of the workflow that I have created to give the overall view of the workflow design.

1. Microsoft Graph API to read the Excel range of records.

I am using the Excel Range Operations to get the range of cells from the excel file, for more details on the Graph API for Excel, you may refer to Microsoft Graph – Documentation – Excel , here is how the Get request forms: 

GET /{version}/me/drive/items/{item-id}/workbook/worksheets(<id|name>)/range(address='<address>’)
authorization: Bearer {access-token}
workbook-session-id: {session-id}

Example of my URL to get excel range from the excel file in a Group’s drive:…
Smiley Very Happy


Here is the example on how you configure it in Workflow Cloud:

The Response content of this action is saved to the resContent variable as shown. We will be interested to look at the “Values” of the returned JSON content.

2. Extract “values” from the returned JSON content

We use the “Query JSON” action to extract the “values” from the returned JSON content that was saved to resContent variable. The “Query JSON” action gives us row variable with value of [ [“Alice”, “Kho”, ““, “Abc o.” ],  [ “Jason “, “Smith”, ““, “Ntxte07” ], [  “”,  “”,  “”, “” ] ] as shown below.

3. Convert “values” string to Collection

Apply a regular expression” to convert that single string of text (i.e. row variable) into array/collection of string and save it to rows collection variable, The Extract operation of the Regular Expression using the Pattern of (?<=\[)[^\[\]].*?(?=\])+ gives us the outcome of rows collection with three items as shown.

4. Get fields of each row of attendance records

Start a loop” logic action to loop through the rows collection to “get item from collection” to get each of the item in the rows collection and save it to row variable. The following regular expression with pattern = (?<=\”)[^\,].*?(?=\”)+ extracts each of the field from the row and saved it to fields collection variable.

That shows us how we get the attendance list row by row from the Excel file that was saved in a Group drive.  

5. Create leads in SalesForce

We can simply use the SalesForce “Create a record” action to create leads in SalesForce. here is how it’s configured in Workflow Cloud using the “fields” collected from excel.

The diagram below illustrates the complete workflow design in Nintex Workflow Cloud