شروع:1395/08/23 05:13 ب.ظ
Picture Placeholder: mostafa rafiei
Picture Placeholder: mostafa rafiei
  • mostafa rafiei

استارت ورک فلو با جاوااسکریپت

Check out http://www.viewmaster365.com/#/How and http://www.viewmaster365.com/#/Create/ActionDelete

It step by step explains how to execute JavaScript from a Calculated Column.

The ID for an item is available on the Table Row, because a Calculated Formula is displayed inside that TR structure;
all you have to do is:

var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}

to get to that TR and its iid attribute

var ID=TR.iid.split(',')[1]

Note that you can get the List GUID from the current context.

var ctx = new SP.ClientContext.get_current();
var listGuid = SP.ListOperation.Selection.getSelectedList();

The Workflow GUID you have to do some more JavaScript digging for, but hardcoding is the easiest option.

Please post the code you come up or have problems with; it is on my (long) list of todos to write an Example for this on the ViewMaster365 site

Client Side Rendering

Ofcourse on SharePoint 2013 you can also do this with CSR. But you have to add an extra JS file and JSlinks on every View you want it applied.

In a Calculated Column it just works.

Update #1

This Formula in a Calculated Column set to datatype=Number will get you started;
I haven't tested if the URL from your original post actually starts a workflow.

="<button style=""cursor:pointer;"" onclick=""{"
&"event.preventDefault();"
&"var clientContext=new SP.ClientContext.get_current();"
&"var listGUID=SP.ListOperation.Selection.getSelectedList();"
&"var workflowGUID='{F704E402-6DA6-4C75-AA97-FBC6F2BEA69F}';"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}" 
&"var url='https://mysharepointurl/_layouts/15/IniWrkflIP.aspx?List='+listGUID;" 
&"url += '&TemplateID='+workflowGUID;" 
&"url += '&ID='+TR.id.split(',')[1];" 
&"alert(url);"
&"SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog',{url:url});"
&"}"">Collect Signature</button>"

Update #2

Took me a day to wade trhu all the blogs with partial (and bloated) answers out there...

Yes the Workflow GUID changes every time you make a change. So you have to query the Workflow Subscriptions on the List, a matching Name gives you the ID (but you need the 'Subscription' to start a workflow, Not the GUID)
Alas the library sp.workflowservices.js needed for this is not available on the List view page; so some extra scripting is required to load it if needed (only for the first button you click)

This immediatly starts the Workflow, no pages in between

Copy/Paste in a Calculated Column, set the datatype to Number

="<button style=""cursor:pointer;"" onclick=""{"
&"event.preventDefault();"
&"function startWorkflow(itemID, wfName) {"
&"  function __startWorkflow() {"
&"      var ctx = new SP.ClientContext.get_current(),"
&"          wfsManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx,ctx.get_web()),"
&"          wfSubs = wfsManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList(_spPageContextInfo.pageListId);"
&"      ctx.load(wfSubs);"
&"      ctx.executeQueryAsync(function () {"
&"          wfsEnum = wfSubs.getEnumerator();"
&"          while (wfsEnum.moveNext()) {"
&"              var wfSub = wfsEnum.get_current();"
&"              if (wfSub.get_name() === wfName) {"
&"                  wfsManager.getWorkflowInstanceService().startWorkflowOnListItem(wfSub,itemID,new Object());"
&"                  SP.UI.Notify.addNotification('Init Workflow: '+wfName+' on item: '+itemID, false);"
&"              }}});}"
&"  if (!SP.WorkflowServices) {"
&"      var script = document.createElement('script');"
&"      script.src = '/_layouts/15/sp.workflowservices.js';"
&"      script.onload = __startWorkflow;"
&"      document.head.appendChild(script);"
&"  } else {__startWorkflow();}"
&"}"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"    
&"startWorkflow(TR.id.split(',')[1] , 'YOUR_WORKFLOW_TITLE_GOES_HERE');"
&"}"">Collect Signature</button>"

Should work on any site, no need to change URLs, all you need to change is: YOUR_WORKFLOW_TITLE_GOES_HERE
There is no error checking at all, I debugged with a simple Send-Email workflow.

Fun with Calculated Columns

You can apply all your Calculated Formula skills; since Formula contents are beign evaluated on every Item change you are essentially creating a kind of self-modyfing JavaScript code.

&"startWorkflow(TR.id.split(',')[1] , 'YOUR_WORKFLOW_TITLE_GOES_HERE');"

Change it to select different Workflows based on a (task) Status:

&"startWorkflow(TR.id.split(',')[1] , '"
  &IF(Status="Approved","MyUnApproveWF","CollectSignatureWF")
&"');"

ICC IWF

http://www.viewmaster365.com/#/Create/ActionDelete

http://www.viewmaster365.com/#/How

Picture Placeholder: mostafa rafiei
  • mostafa rafiei
/_layouts/15/images/person.gif" alt="Picture Placeholder: mostafa rafiei" />
mostafa rafiei

Check out http://www.viewmaster365.com/#/How and http://www.viewmaster365.com/#/Create/ActionDelete

It step by step explains how to execute JavaScript from a Calculated Column.

The ID for an item is available on the Table Row, because a Calculated Formula is displayed inside that TR structure;
all you have to do is:

var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}

to get to that TR and its iid attribute

var ID=TR.iid.split(',')[1]

Note that you can get the List GUID from the current context.

var ctx = new SP.ClientContext.get_current();
var listGuid = SP.ListOperation.Selection.getSelectedList();

The Workflow GUID you have to do some more JavaScript digging for, but hardcoding is the easiest option.

Please post the code you come up or have problems with; it is on my (long) list of todos to write an Example for this on the ViewMaster365 site

Client Side Rendering

Ofcourse on SharePoint 2013 you can also do this with CSR. But you have to add an extra JS file and JSlinks on every View you want it applied.

In a Calculated Column it just works.

Update #1

This Formula in a Calculated Column set to datatype=Number will get you started;
I haven't tested if the URL from your original post actually starts a workflow.

="<button style=""cursor:pointer;"" onclick=""{"
&"event.preventDefault();"
&"var clientContext=new SP.ClientContext.get_current();"
&"var listGUID=SP.ListOperation.Selection.getSelectedList();"
&"var workflowGUID='{F704E402-6DA6-4C75-AA97-FBC6F2BEA69F}';"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}" 
&"var url='https://mysharepointurl/_layouts/15/IniWrkflIP.aspx?List='+listGUID;" 
&"url += '&TemplateID='+workflowGUID;" 
&"url += '&ID='+TR.id.split(',')[1];" 
&"alert(url);"
&"SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog',{url:url});"
&"}"">Collect Signature</button>"

Update #2

Took me a day to wade trhu all the blogs with partial (and bloated) answers out there...

Yes the Workflow GUID changes every time you make a change. So you have to query the Workflow Subscriptions on the List, a matching Name gives you the ID (but you need the 'Subscription' to start a workflow, Not the GUID)
Alas the library sp.workflowservices.js needed for this is not available on the List view page; so some extra scripting is required to load it if needed (only for the first button you click)

This immediatly starts the Workflow, no pages in between

Copy/Paste in a Calculated Column, set the datatype to Number

="<button style=""cursor:pointer;"" onclick=""{"
&"event.preventDefault();"
&"function startWorkflow(itemID, wfName) {"
&"  function __startWorkflow() {"
&"      var ctx = new SP.ClientContext.get_current(),"
&"          wfsManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx,ctx.get_web()),"
&"          wfSubs = wfsManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList(_spPageContextInfo.pageListId);"
&"      ctx.load(wfSubs);"
&"      ctx.executeQueryAsync(function () {"
&"          wfsEnum = wfSubs.getEnumerator();"
&"          while (wfsEnum.moveNext()) {"
&"              var wfSub = wfsEnum.get_current();"
&"              if (wfSub.get_name() === wfName) {"
&"                  wfsManager.getWorkflowInstanceService().startWorkflowOnListItem(wfSub,itemID,new Object());"
&"                  SP.UI.Notify.addNotification('Init Workflow: '+wfName+' on item: '+itemID, false);"
&"              }}});}"
&"  if (!SP.WorkflowServices) {"
&"      var script = document.createElement('script');"
&"      script.src = '/_layouts/15/sp.workflowservices.js';"
&"      script.onload = __startWorkflow;"
&"      document.head.appendChild(script);"
&"  } else {__startWorkflow();}"
&"}"
&"var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"    
&"startWorkflow(TR.id.split(',')[1] , 'YOUR_WORKFLOW_TITLE_GOES_HERE');"
&"}"">Collect Signature</button>"

Should work on any site, no need to change URLs, all you need to change is: YOUR_WORKFLOW_TITLE_GOES_HERE
There is no error checking at all, I debugged with a simple Send-Email workflow.

Fun with Calculated Columns

You can apply all your Calculated Formula skills; since Formula contents are beign evaluated on every Item change you are essentially creating a kind of self-modyfing JavaScript code.

&"startWorkflow(TR.id.split(',')[1] , 'YOUR_WORKFLOW_TITLE_GOES_HERE');"

Change it to select different Workflows based on a (task) Status:

&"startWorkflow(TR.id.split(',')[1] , '"
  &IF(Status="Approved","MyUnApproveWF","CollectSignatureWF")
&"');"

ICC IWF

http://www.viewmaster365.com/#/Create/ActionDelete

http://www.viewmaster365.com/#/How

01395/08/23 05:13 ب.ظ1395/08/23 05:13 ب.ظخیرAdministration
33/5033321759259
11393/10/23 07:08 ب.ظ1
mostafa rafiei
گفتمانی برای نمایش وجود ندارد