
Announcements
Hi all,
On an advanced form I have a button that triggers a workflow (OOB button, not custom).
The problem is that it does not save form data, it only triggers the workflow.
I tried to change its behaviour using the following code. Not working. At some time I managed to save the data, but still the workflow was not triggered. Is there any simpler way to accomplish this?
$(document).ready(function () {
var contactid = "{{ user.contactid }}";
var workflowButton = $(".workflow-link.btn.btn-primary.button.btn");
workflowButton.bind("click", function () {
var dataUrl = workflowButton.attr("data-url");
if (!!dataUrl) {
workflowButton.attr("data-url-prevent", dataUrl);
workflowButton.removeAttr("data-url");
WebForm_DoPostBackWithOptions
(new WebForm_PostBackOptions($(this).prev().attr("name"), '', true, '', '', false, true));
executeWorkflow();
}
})
function executeWorkflow() {
debugger;
var u = "/_services/execute-workflow/6d6b3012-e709-4c45-a00d-df4b3befc518"; // execute workflow request url
var params = {};
var workflow = {};
workflow.LogicalName = "workflow";
workflow.Id = "e85806bc-78ae-ec11-983e-000d3ab94e86";
var data = {};
data.LogicalName = "contact";
data.Id = contactid; // guid of the contact record.
params.workflow = workflow;
params.entity = data;
var jData = JSON.stringify(params);
shell.ajaxSafePost({
type: "POST",
contentType: "application/json",
url: u,
data: jData
}).done(function (r) {
debugger;
}).fail(function (n) {
debugger;
});
}
});