Tuesday, May 22, 2018

Go to workflow initiation form on button click in SharePoint list view

   /*Put this code on Page*/


function StartWorkflowJsLink(overrideCtx) {
        /*If you have multiple list views on page better hard code this ListID Variable*/
        var ListID = overrideCtx.listName;
        var ItemGuid = '';
        /*Replace Template ID*/
        var TemplateID = '{7f51f2f1-1bc9-42d9-86a8-2e0c34fa3323}'; /* Get it from workflow start page URL. It will be changed everytime you republish the workflow.*/
        var SourceURL = window.location.href;
        var ItemID = overrideCtx.CurrentItem.ID;
        var webAbsoluteURL = _spPageContextInfo.webAbsoluteUrl;
        var WFPageURL = '/_layouts/15/NintexWorkflow/StartWorkflow.aspx?';

        debugger;
        var workflowURL = webAbsoluteURL + WFPageURL + 'List=' + ListID + '&ID=' + ItemID + '&TemplateID=' + TemplateID + '&Source=' + SourceURL;
        var btnHTML = btnHTML = "<input type=\"button\" onclick=\"GotoWFStartPage('" + workflowURL + "');\" value=\"Start Workflow\"></input>";
        return btnHTML;

    }

function GotoWFStartPage(workflowURL) {


    window.location.href = workflowURL;

}


function registerListRenderer() {

    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'Edit': {
            'View': StartWorkflowJsLink
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
}



ExecuteOrDelayUntilScriptLoaded(registerListRenderer, 'clienttemplates.js');


/*Code Ends*/

Wednesday, May 16, 2018

Parse XML using Microsoft Flow

* For any help in Nintex & MS Flow drop a comment.

Here I will take sample xml and try to parse it using Microsoft flow. Below is the screenshot of full flow.


  1. In this flow I am adding button as flow trigger however you can add this logic in your flow under any trigger.
  2. Next , I added compose action (renamed to XML Data) and added the sample XML as shown below.
        Sample XML
       <?xml version="1.0"?>
       <Countries>
               <Country type="System.String">ABC</Country>
<Country type="System.String">XYZ</Country >
         </Countries>



      3. Add one more compose action(renamed to Use xpath) where we will use xpath to get the xml nodes as shown below.
           
          
           Formula used in this compose action:
           xpath(xml(outputs('XML_Data')),'//Country')
   
  • In xpath expression, first parameter asks for xml data. So we used xml() action to convert our data into valid xml form.
  • Second parameter asks for expression to specify which node to read.
  • //Country means it will parse xml and get all the “<Country>” nodes irrespective of it’s location.
  • Output of step 3 would be array of  
  • "<Country type="System.String">India</Country>" and "<Country type="System.String">Japan</Country>" 

     4. Since we have multiple “<Country>” nodes, so output will be an array. 
     5. To read array use “Apply to Each” action and add the output of xpath action from previous action as parameter as shown below.

     6. Insert a compose action renamed as (Get Current Node Text) inside apply to each              loop to read the current node of array as shown above.
     7. Use this xpath expression to get current node as text.
         xpath(xml(item()),'string(.)')
     8. Now run the flow you will get Countries as text as shown below.