Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - General Discussions
Unanswered

Not able to trigger PowerApps process workflow through javascript in power pages

(0) ShareShare
ReportReport
Posted on by 44

Hi everyone, I am trying to trigger process workflow on custom button click using javascript on power pages, But the post request is giving me unauthorized error.

Please help if anyone is aware how we can achieve this.

Categories:
  • Peragin Profile Picture
    160 on at
    Re: Not able to trigger PowerApps process workflow through javascript in power pages

    Can it be a power automate instead? There is native support for calling those now: https://youtu.be/JS16v3xBLFU 

  • fm_skeller Profile Picture
    277 Super User 2025 Season 1 on at
    Re: Not able to trigger PowerApps process workflow through javascript in power pages

    @Pragatij the way you are trying to call the workflow won't work. You cannot access the CRM webapi from the portal.
    From power pages, you can call a workflow like this:

    var url = "/_services/execute-workflow/<your website id>";
    var data = {};
    var workflowReference = {};
    workflowReference.LogicalName = "workflow";
    workflowReference.Id = workflowid;
    data.workflow = workflowReference;
    var entityReference = {};
    entityReference.LogicalName = entityName;
    entityReference.Id = id;
    data.entity = entityReference;
    var json = JSON.stringify(data);
    shell.ajaxSafePost({
    	type: "POST",
    	contentType: "application/json",
    	url: url,
    	data: json
    }).done(function() {
    	//workflow executed successfully
    }).fail(function(e) {
     //workflow failed for some reason
    }) 
  • Pragatij Profile Picture
    44 on at
    Re: Not able to trigger PowerApps process workflow through javascript in power pages

    @fm_skeller 

    I am using below javascript code 

    function triggerOnDemandWorkflow() {
    console.log("Inside Function");
    var entityId = document.getElementById('EntityFormView_EntityID');
    var entity = {
    "EntityId": entityId.value
    };
    console.log(entityId.value);

    var WorkflowId = "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX";

    fetch(
    "https://oooooo.api.crm.dynamics.com/api/data/v9.2/workflows(" + WorkflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow",
    {
    body: "{\"EntityId\":\"" + entityId.value + "\"}",
    credentials: "same-origin",
    headers: {
    "Accept": "application/json",
    "Content-Type": "application/json; charset=utf-8",
    "OData-MaxVersion": "4.0",
    "OData-Version": "4.0"
    },
    method: "POST"
    })
    .then(response => console.log("Success:", response))
    .catch(error => console.error("Error:", error));

    }

     

    and this is the error which I am getting on execution above function on button click 

    Pragatij_0-1706867545576.png

     

  • fm_skeller Profile Picture
    277 Super User 2025 Season 1 on at
    Re: Not able to trigger PowerApps process workflow through javascript in power pages

    What Javascript are you using to trigger the workflow?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >