Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Dynamics API setActiveProcess fails on Opportunity records

Posted on by Microsoft Employee

I'm attempting to automatically set the process of an Opportunity record to the 'Lead to Opportunity Sales Process'. So far I have tried both Power Automate / Flow and programmatically with Javascript via a web resource on the Form Properties.

Setting Using Javascript

This method works flawlessly on a Lead record, but on an Opportunity I receive the error 'POST /api/data/v9.0/SetProcess 500' 

function setBPF(executionContext) {
  var formContext = executionContext.getFormContext();
  console.log("Checking business process flow.");
  if (formContext.data.process.getActiveProcess()) {
    console.log("Business process flow found.");
    var activeProcessID = formContext.data.process.getActiveProcess().getId();
    if (activeProcessID.toUpperCase() != "919E14D1-6489-4852-ABD0-A63A6ECAAC5D") {
      formContext.data.process.setActiveProcess("919E14D1-6489-4852-ABD0-A63A6ECAAC5D", callBackFunction);
    } else {
      console.log("Business process flow is already set.");
    }
  } else {
      console.log("Business process flow is NULL.");
      formContext.data.process.setActiveProcess("919E14D1-6489-4852-ABD0-A63A6ECAAC5D", callBackFunction);
    }
};



function callBackFunction(result) {
  if (result == "success") {
    console.log("Business process flow updated.");
  } else {
  console.log("Business process flow was not updated.");
  }
};

Setting Using Power Automate / Flow

This method seems to set the Process ID value fine, but when the record is loaded the Lead to Opportunity Sales Process UI is not visible at the top of the record. Further, the above Javascript reports that the activeProcess is still null when applied.

When a new record is created in Dynamics with a type of Lead > Update record 'Process ID' to '919E14D1-6489-4852-ABD0-A63A6ECAAC5D'

I would prefer the first solution, but we often mass-qualify our Leads and so the record is never opened (and thus the Process isn't set). Because of this I would like to use the same logic on an Opportunity, but receive a 500 error:

POST /api/data/v9.0/SetProcess 500

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics API setActiveProcess fails on Opportunity records

    RajarajanS - I have answered your questions.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics API setActiveProcess fails on Opportunity records

    Yes, as the title states it does not work on Opportunity records, only Leads. And I am attempting to use it specifically on existing records. The documentation has been no help, the code should work on all existing records regardless of entity type, from what I understand.

  • Verified answer
    RajarajanS Profile Picture
    RajarajanS on at
    RE: Dynamics API setActiveProcess fails on Opportunity records

    Hello Partner, 

    Is this JS failing on opportunity records? If so, are you trying to update the BPF to the opportunity records that are created newly or existing ones.

    As of yet, SetActiveProcess Client API is not supported on Create Forms but it should ideally work fine on update forms. 

    Refer to article: https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/formcontext-data-process/activeprocess/setactiveprocess general usage of this API>

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans