DYNAMICS 365 PORTAL HOW TO CALL AND EXECUTE WORKFLOW
Calling Dynamics 365 Workflows from portals can only be done by configuring and adding buttons in entity lists or entity forms.
However, and for some requirements, you need to call a workflow from a web page that does not contain entity list nor entity form.
So, how do we do this?
All portal pages automatically include a JS reference to the file js\antiforgerytoken.js that contains an object named
shell which has a method called ajaxSafePost that can be used and let you achieve request calls to the server.
How do we use this function to call workflow from the portal? Below is an example of how you could use the ajaxSafePost method
to invoke the execute workflow service.
-
I've created the below function that take the parameters needed to execute the workflow
function ExecuteWorkflow(workflowId, entityLogicalName, recordId) {
var urlService = "/_services/execute-workflow/41655177-b47f-ec11-8d21-000d3a4b649d"; // execute workflow URL
var params = {};
var workflow = {};
workflow.LogicalName = "workflow";
workflow.Id = workflowId; // guid of the workflow to execute
var data = {};
data.LogicalName = entityLogicalName; // logical name of the target entity
data.Id = recordId; // guid of the target record
params.workflow = workflow;
params.entity = data;
var jData = JSON.stringify(params);
shell.ajaxSafePost({
type: "POST",
contentType: "application/json",
url: urlService,
data: jData
}).done(function (r) {
//do something
}).fail(function (n) {
//do something
});
} -
How do you get the execute workflow request URL?
You can do it by adding a temporary call workflow button on an entity list or an entity form, and by using the Developer tools (F12) of your browser, you will be able to get the workflow url service from the data-url property as per the below image
Bonus Tips:
- This method is tested on the Dynamics Portal Community on-premise edition
- The workflow to be executed from the Portal should be triggered on-demand
You can check this page
for more portal-related articles like :
Hope This Helps!
Comments
Post a Comment