cancel
Showing results for 
Search instead for 
Did you mean: 
waryoldguy
Nintex Newbie

Run workflow on selected list/library items

Jump to solution

I would like to create a workflow that creates an item in a separate list, that is linked (using Related Items field), to the selected documents in a Library. In essence, I want to query the library for items that are selected; build a collection of these; then loop through that collection to build the string for the related items, and update the field in the newly created item. The last bits, are very doable, it is getting the selected items in to a collection that I am a bit fuzzy on.

 

Is this recreational impossibility, or should I be able to do this?

 

Thanks.

Labels: (1)
0 Kudos
Reply
7 Replies
Automation Master
Automation Master

Re: Run workflow on selected list/library items

Jump to solution

I think you could come up with something close - if you had a metadata field that you marked (ShouldRunWorkflow): (such as yes/no) and then you could query all the items with this metadata marked as yes and have the workflow query for this list and act on them collectively.   You could then have the workflow reset this value to No in case you wanted it to run again or not run again at another time.   This is just a quick thought, but might get you started in the right direction.

-Mike

0 Kudos
Reply
waryoldguy
Nintex Newbie

Re: Run workflow on selected list/library items

Jump to solution

Thanks. I think I saw something like that on another thread, but want to avoid adding a field that users would have to change.

If I were doing this, that might be OK, but this is for end users...so I cannot make them set a field, it is enough to get them to select multiple items. Even though the idea is the same, it is different enough to cause friction.

It would appear that I need to use client side script to accomplish this. Certainly makes sense, since each client may have a different selection. That also speaks to not using a field, since multiple users might be setting values at the same time.

0 Kudos
Reply
janeyres
Nintex Newbie

Re: Run workflow on selected list/library items

Jump to solution

Hi John,

 

You can do this with client side rendering. I've pasted a very simple version of the script you'll need below, you'll need to edit it to point at the correct workflow and list name. For simplicity I've added the item ID as the last column in the list view so I can find it easily, then just use the following script as your JS Link source:

 

(function () {
  
    (window.jQuery || document.write('<script src="//ajax.aspnetcdn.com/ajax/jquery/jquery-1.10.0.min.js"><\/script>'));

    var viewContext = {};
    viewContext.Templates = {};

    viewContext.Templates.Footer = "<div><input type='button' Value='Start Workflow on ID for Selected' onclick='StartWorkflowOnSelectedItems();'></div>";
  
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(viewContext);

})();

function StartWorkflowOnSelectedItems()


  $('.s4-itm-selected').each(function(){   

    var listitemid = $(this).find('.ms-vb-lastCell')[0].innerText; 
    startworkflowonlistitemcsr("Workflow Name", listitemid , "List Name");

  });

}

function startworkflowonlistitemcsr(wfName, itemId, listName) {
  

    var associationData = '';
    var webMethod = _spPageContextInfo.webAbsoluteUrl + '/_vti_bin/NintexWorkflow/Workflow.asmx';
    var soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                            "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                              "<soap:Body>" +
                                "<StartWorkflowOnListItem xmlns=\"http://nintex.com\">" +
                                  "<itemId>" + itemId + "</itemId>" +
                                  "<listName>" + listName + "</listName>" +
                                  "<workflowName>" + wfName + "</workflowName>" +
                                  "<associationData></associationData>" +
                                "</StartWorkflowOnListItem>" +
                              "</soap:Body>" +
                            "</soap:Envelope>";

    $.ajax({
        type: "POST",
        url: webMethod,
        beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://nintex.com/StartWorkflowOnListItem"); },
        data: soap,
        contentType: "text/xml; charset=utf-8",
        dataType: "xml",
        success: function (data) {
           
        },
        error: function (e) {         
           
        }

    });
}

 

Jan

View solution in original post

Reply
waryoldguy
Nintex Newbie

Re: Run workflow on selected list/library items

Jump to solution

Jan,

Thanks so much. In this case, the need for this has receded (it had been voiced by someone other than those who would actually use the feature), but I can absolutely see the need for this capability for several other processes we have.

Regards,

   John

0 Kudos
Reply
Not applicable

Re: Run workflow on selected list/library items

Jump to solution

Hi Jan,

This looks brilliant , can you please let me know where do I paste this script it is just behind a javascript "start" button

Thanks

Ash

0 Kudos
Reply
janeyres
Nintex Newbie

Re: Run workflow on selected list/library items

Jump to solution

Hi,

This is SharePoint's client side rendering logic, you'll need to upload the script to the master page gallery and then reference it in the JS Link property on the view web part. An overview is here, Introduction to Client-Side Rendering in SharePoint 2013 | Kaptyn

Jan

Reply
Not applicable

Re: Run workflow on selected list/library items

Jump to solution

Thanks

0 Kudos
Reply