Couldn't trigger workflow from JavaScript embedded in Nintext Forms for Office 365

  • 21 March 2018
  • 9 replies

Hi Everyone,

I am working on a Nintex forms for office 365. I want to trigger a workflow on click of a button(which will trigger a javascript function) in Nintext Forms(for Office 365) and once the workflow is completed, I want to navigate to a url.

I am facing challenge while triggering the workflow. The Soap service for Nintex works in 2010 Nintex but it is not working in Nintex for Office 365 environment.

Thanks in advance for your help.

Best regards,


9 replies

Hi Tushar,

seems like the Nintex Online REST Api doesn't offer anything to help us here. Is it a list workflow you are trying to trigger? Would it be an option to not start the workflow directly but to create a list item via regular SharePoint Online REST endpoint and have the workflow triggered on item creation? I don't really like this as you will have to create an item for actually nothing but at least it would start your workflow.

If anyone has a better idea I'd love to hear that!



Thanks for your reply ‌.

Actually I want to copy the current item into a new item and navigate the user to edit form of newly created item on click of a button in Nintex form.

That is why I wanted to trigger the workflow on button click, then once the workflow is completed, I want to navigate to the Edit form.

Hope you understand my problem statement here. 

You mean you only need the workflow for copying the item? Can't you use plain REST for creating the item? This way you should be able to create the link to the edit form of the newly created item manually and redirect the user to that page.

Have you tried debugging the code via your browsers dev tools?

Yeah. I did. I have embedded this JavaScript code in a SharePoint page with the help of Content Editor Web Part.

I have the issue at the post call shown below which gives me error: ""{"error":{"code":"-2147024883, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The data is invalid. (Exception from HRESULT: 0x8007000D)"}}}""

var binary= buffer;//this is the data I got from List Item attachment Attachment file 
        //Attach file as attachment - Start
        var postRequestUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + listname + "')/items(" + id + ")/AttachmentFiles/add(FileName='" + filename + "')";

            type: "POST",
            url: postRequestUrl,
            headers: {
                "Accept": "application/json; odata=verbose",
                "X-RequestDigest": $('#__REQUESTDIGEST').val()
            contentType: "application/json;odata=verbose",
            binaryStringRequestBody: true,
            body: binary,
            success: function (data) {
                console.log(data + ' uploaded successfully');
            error: function (err) {
                console.log(filename + "not uploaded error");
            state: "Update"

What file have you tried to upload? Did you make sure there is content in the file? For example you cannot upload empty word docs into sharepoint.

Hi Phillip,

There is a content in the file. It is not empty.

By the way, do you have any idea how we can copy the attachments from one item to another using REST of JSOM in SharePoint online? 

Thanks in advance.

Haven't done this myself but this looks promising:

office 365 - copy the attachments of a list item in CSOM - SharePoint Stack Exchange 

Userlevel 4
Badge +16

Moderator edit (this reply was not migrated)

Philipp Lucas‌, I did the same. Item creation is successful for me. I am struggling at the part where I need to copy the attachments from old Item to new item. 

I ahevd used below referances: 

SharePoint 2013 - Uploading Multiple Attachments To The New Item On List Using JSOM And REST API 

Tech and me: How to copy files between sites using JavaScript REST in Office365 / SharePoint 2013  


But now, when I am using POST, it is throwing an error : ""{"error":{"code":"-2147024883, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The data is invalid. (Exception from HRESULT: 0x8007000D)"}}}""


Please find my code below:

//Function to get Querystring Parameter by name
function getParameterByName(name, url) {
    if (!url) {
        url = window.location.href;
    name = name.replace(/[[]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/+/g, " "));

var riskProcessing = riskProcessing || {};

riskProcessing.copyService = function ($, listTitle) {
    var self = this;

    self.defaultTab = "1.";

    self.copyItem = copyItem;

    self.listEditFormUrl = ";

    self.listTitle = "Risk Processing";
    var fieldCollection, newListItem, itemUrl, attachmentFilesFromSource, newListItemID, digestValue;

    var attachments = [];
    function copyItem(itemId, newTitle) {
        digestValue = $('#__REQUESTDIGEST').val();" ", "Copying data from selected item.\nYou will be redirected to the copied item shortly.\nPlease wait...");
        var clientContext = new SP.ClientContext.get_current();
        var web = clientContext.get_web();
        var list = web.get_lists().getByTitle(self.listTitle);
        fieldCollection = list.get_fields();
        var itemToCopy = riskProcessing.getItemById(list, itemId);

        clientContext.executeQueryAsync(function () {
            var listId = list.get_id().toString().toUpperCase();
            var missingFields = [];
            itemToCopy = riskProcessing.selectFirstItem(itemToCopy);
            var itemRPClient = itemToCopy.get_item("RPClient");

            //Create New Item and assign the values same as in Copy Workflow
            var itemCreateInfo = new SP.ListItemCreationInformation();
            newListItem = list.addItem(itemCreateInfo);
            clientContext.executeQueryAsync(function () {
                itemUrl = _spPageContextInfo.webAbsoluteUrl + "/_layouts/listform.aspx?PageType=6&ListId={" + listId + "}&ID=" + newListItem.get_id() + "&Source=" + _spPageContextInfo.webAbsoluteUrl;
                console.warn('itemUrl: ' + itemUrl);
                newListItemID = newListItem.get_id()
                newListItem = list.getItemById(newListItemID);

                //enumerate the list fields and update values
                var fieldEnumerator = fieldCollection.getEnumerator();
                while (fieldEnumerator.moveNext()) {
                    var oField = fieldEnumerator.get_current();
                    //exclude fields
                    if ((!oField.get_readOnlyField())
                        && (oField.get_internalName() != "Attachments")
                        && (!oField.get_hidden())) {
                        //get value of source field

                        try {
                            var sourceVal = itemToCopy.get_item(oField.get_internalName());
                            if (sourceVal != null) {
                                //set value on new item
                                newListItem.set_item(oField.get_internalName(), sourceVal);
                        catch (ex) {

                console.log('Missing Fields:')
                //Update Fields
                newListItem.set_item('Title', 'new title');

                clientContext.executeQueryAsync(function () {
                    //Update success handler function

                    var attachmentFolder = web.getFolderByServerRelativeUrl('Lists/Risk Processing/Attachments/' + itemId);

                    attachmentFilesFromSource = attachmentFolder.get_files();


                    clientContext.executeQueryAsync(function () {
                        //success getting attachments
                        var i = 0;
                        var attachmentFilesCount = attachmentFilesFromSource.get_count();

                        var promisesArr = [], promisesArr1 = [];
                        for (var file in attachmentFilesFromSource) {
                            if (attachmentFilesFromSource.itemAt(i) !== undefined && attachmentFilesFromSource.itemAt(i) !== null) {
                                var fileServerRelativeUrl = attachmentFilesFromSource.itemAt(i).get_serverRelativeUrl();
                                var fileName = attachmentFilesFromSource.itemAt(i).get_name();

                                var p = GetAttachmentData(newListItemID, self.listTitle, fileName, fileServerRelativeUrl);
                            else {

                        $.when.apply($, promisesArr).then(function (schemas) {
                            console.log('attachments:'); console.log(attachments);
                            for (var i = 0; i < attachments.length; i++) {
                                var attachment = attachments[i];
                                var p1 = UploadFileAsAttachment(attachment.Listname, attachment.ItemID, attachment.Filename, attachment.Body);

                            $.when.apply($, promisesArr1).then(function (schemas1) {