问题
**I have created a custom edit form for a SharePoint online custom list. Where I have created a custom button via which I will start a Workflow.
the issue is I am not able to call that function on button click. I have used a single comma also for the function call
I have created a custom edit form for a SharePoint online custom list. Where I have created a custom button via which I will start a Workflow. The issue is I am not able to call that function on button click. I have used a single comma also for function call**
HTML Button Code:
<td class="ms-toolbar" nowrap="nowrap" align="right">
<input type="button" runat="server" value="Assign To Next Step" name="AssignToNextStep" onClick="startWorkflow()"/>
</td>
JavaScript Function Code is:
<script type="text/javascript">
function startWorkflow()
{
alert("Inside");
try
{
showInProgressDialog();
var ctx = SP.ClientContext.get_current();
var wfManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web());
var subscription = wfManager.getWorkflowSubscriptionService().getSubscription("My Workflow ID");
ctx.load(subscription, 'PropertyDefinitions');
ctx.executeQueryAsync(
function(sender, args)
{
wfManager.getWorkflowInstanceService().startWorkflow(subscription, "");
ctx.executeQueryAsync(
function(sender, args)
{
closeInProgressDialog();
},
function (sender, args)
{
closeInProgressDialog();
alert(errorMessage);
});
});
}
catch(ex)
{
alert(ex);
dlg.close();
}
}
</script>
回答1:
That Function was out of Scope. I mean I just changed the place of that function.
回答2:
How do you insert the code? Have you checked the developer tools in your browser if it shows any errors?
Try to add
onClick="startWorkflow();return false;"
In your code.
来源:https://stackoverflow.com/questions/49109060/not-able-to-call-javascript-function-on-onclick-event