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

Start Site Workflow using webservice and javascript Button

I know there are quite a bit of similar posts on this topic. But none of the solutiouns seem to work for me. There is one that's very close located here https://community.nintex.com/t5/Nintex-for-SharePoint/Start-a-site-workflow-using-Javascript/m-p/701...
I've reused the script but not sure of A. how to get the associatedData and B. to properly create the button to put on my page. A little background it's a site workflow that queries a number of other lists to find any workflow errors and puts the numbers in a dashboard. On that page I would like a button so they can refresh the dashboard on the fly. A million thanks in advance for any help.
P.S. we do not have Nintex forms here unfortunatly.

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

Re: Start Site Workflow using webservice and javascript Button

if your workflow doesn't request for any inputs you need not to care about association data.

 

to add a buton on page, add a script editor or html form webpart on the page. configure a HTML snippet for the webpart that creates a button and calls a javascript when clicked.

0 Kudos
Reply
ctoper11
Nintex Newbie

Re: Start Site Workflow using webservice and javascript Button

Thank you for the response. How can I tell completely if it doesn't require any inputs? Also I'm using the js in that post I linked to. I can just pull out the associationData line?

0 Kudos
Reply
Automation Master
Automation Master

Re: Start Site Workflow using webservice and javascript Button

Thank you for the response. How can I tell completely if it doesn't require any inputs? 

try to start workflow manually and check if there appear some controls on the start form that expect to provide some inputs.

if there are any, you may need to supply respective data within associationData element. but that need not necessarily mean you have to. the workflow may be designed so that if nothing is provided it works with some defaults.

the best would be to discuss that with workflow designer directly.

 

 

 

 I can just pull out the associationData line?

no, associationData element has to be present in the request.

it just means you do not need to provide anything within associationData element body

 

see documentation how to work with association data

https://help.nintex.com/en-US/sdks/sdk2013/#Operational/SDK_NW_OPS_WorkflowsAssocData.htm

 

0 Kudos
Reply
ctoper11
Nintex Newbie

Re: Start Site Workflow using webservice and javascript Button

OK so there are no inputs to be provided so I'm leaving the associationData element blank. I'm using the below script to run the javascript
<script type="text/javascript" src="https://MySite.org/Test/PublicForms/SiteAssets/jquery-1.11.1.min.js"></script>
<input type="Button" onclick="https://MySite.org/Test/public/SiteAssets/jQueryLibraries/StartSiteWorkflow.js" value="REFRESH LIST">
</script>
And the StartSiteWorkflow.js is:

function ResetLetter() {
var waitingDialog;
// var waitingDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Your action is in progress...', "Please wait while we generate the tasks for you.");
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
waitingDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Your action is in progress...', "Please wait while we generate the tasks for you.");
});

var $request = new Sys.Net.WebRequest();
var siteUrl = "https://MySite.org/Test/public/SiteAssets/public/CommonRequest";
$request.set_url((siteUrl || _spPageContextInfo.webServerRelativeUrl.replace(/^\s+|\s+$/gi, '')) + "/_vti_bin/NintexWorkflow/Workflow.asmx");
var $headers = $request.get_headers();
$headers["Content-Type"] = "text/xml; charset=utf-8";
$headers["SOAPAction"] = "http://nintex.com/StartSiteWorkflow";
$body = "<?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>" +
"<StartSiteWorkflow xmlns=\"http://nintex.com\">" +
"<workflowName>MyWorkflowDashboard</workflowName>" +
"<AssociationData></associationData>" +
"</StartSiteWorkflow>" +
"</soap:Body>" +
"</soap:Envelope>";
var thisArgs = this;
$request.add_completed(function (executor, args) {
var statusCode = executor.get_statusCode();
if (statusCode >= 200 && statusCode <= 399) {
Sys.Debug.trace("Action terminated");
} else {
Sys.Debug.trace('Warning : Error (Status code {0})', statusCode);
alert('Error');
}
waitingDialog.close();
});

Can you see anything I'm missing? Thank you SO much for all of your help by the way.

0 Kudos
Reply
Automation Master
Automation Master

Re: Start Site Workflow using webservice and javascript Button

haven't tested your whole code, but noticed mistake in button click handler - it has to call javascript function directly, not a javascript file.

StartSiteWorkflow.js script has to be included with a script tag, just like you do for jquery

Reply
ctoper11
Nintex Newbie

Re: Start Site Workflow using webservice and javascript Button

Ok so in the handler if I have it like so:
&lt;script type="text/javascript" src="https://MySite.org/Test/PublicForms/SiteAssets/jquery-1.11.1.min.js">&lt;/script">&lt;/script&gt;
&lt;script type="text/javascript" src="https://MySite.org/Test/public/SiteAssets/jQueryLibraries/StartSiteWorkflow.js">&lt;/script&gt;
What am I putting here as the event?
<input type="Button" onclick="?" value="REFRESH LIST">
0 Kudos
Reply
Automation Master
Automation Master

Re: Start Site Workflow using webservice and javascript Button

as I said, it has to call js function

 

<input type="Button" onclick="ResetLetter()" value="REFRESH LIST">

 

0 Kudos
Reply
ctoper11
Nintex Newbie

Re: Start Site Workflow using webservice and javascript Button

Hi there, the button still isn't working. I did however find a workaround, it's not as elegant but it does work. I created a list with a workflow that does the webservice call to run the site workflow. And the button activates that workflow. A bit cumbersome but it does work. Thanks so so much all of your help.

0 Kudos
Reply
Automation Master
Automation Master

Re: Start Site Workflow using webservice and javascript Button

in between step with list workflow is really not necessary.

i fyou managed to start a list workflow you should be able to start a site one as well. there's not a big difference between the two.

 

I'm not not whether it's just a copy&paste problem, but your above code doesn't seem to be complete resp. syntactilay correct...

0 Kudos
Reply