Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM Rest API - Get Processes with Stages ... can't find way to get Process Order

Posted on by Microsoft Employee

I am trying to figure out how to get my process results in the flow order that they are setup, but I am not sure where that value is stored and how to do an order by to get the results I am looking for:

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/processstages()" + 
         "?$expand=processid($select=*)" +
         "&$filter=primaryentitytypecode eq 'opportunity'" +
         "&$orderby=_processid_value asc,stagecategory", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        console.clear();
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            console.log('Get Process Stages: ', result.value);
        } else {
            console.log(JSON.parse(this.response).error);
        }
    }
};
req.send();


For example the process should be Qualify, Develop, Approval, Close. However you can see in the image below that Close is before Approval.

console.log.png

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Rest API - Get Processes with Stages ... can't find way to get Process Order

    Hmm cause I thought I could use the function RetrieveActivePath and pass the processid

    var parameters = {};
    parameters.ProcessInstanceId = "3e8ebee6-a2bc-4451-9c5f-b146b085413a";
    
    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/RetrieveActivePath()", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            console.clear();
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                console.log('result: ', result);
            } else {
                console.log(JSON.parse(this.response)['error']);
            }
        }
    };
    req.send(JSON.stringify(parameters));


    unfortunately I am getting the following error:

    code: "0x80040203"
    innererror:
    message: "Required field 'ProcessInstanceId' is missing"
    stacktrace: "   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)
    ↵   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Execute(OrganizationRequest request, ExecutionContext executionContext)
    ↵   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)
    ↵   at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)
    ↵   at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass12_0.<GetUnboundFunction>b__0()
    ↵   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)
    ↵   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)
    ↵   at lambda_method(Closure , Object , Object[] )
    ↵   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
    ↵   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
    ↵--- End of stack trace from previous location where exception was thrown ---
    ↵   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    ↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    ↵   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
    ↵--- End of stack trace from previous location where exception was thrown ---
    ↵   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    ↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    ↵   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
    ↵--- End of stack trace from previous location where exception was thrown ---
    ↵   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    ↵   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    ↵   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    type: "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]"
    message: "Required field 'ProcessInstanceId' is missing"


  • Suggested answer
    Macoy Profile Picture
    Macoy 275 on at
    RE: CRM Rest API - Get Processes with Stages ... can't find way to get Process Order

    Hi,

    Use D365 Web API instead of CRM REST API, there's this RetrieveActivePath function that you can use and it will give you the collection of stages currently in active path of the BPF.

    docs.microsoft.com/.../retrieveactivepath

    Regards,

    Macoy

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Rest API - Get Processes with Stages ... can't find way to get Process Order

    Wanted to follow-up and see if anyone was able to look into this?  I thought I was onto something under processid with a field called processorder, but no luck on that.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Rest API - Get Processes with Stages ... can't find way to get Process Order

    It appears that it might be defaulting to that, but the flow in my process setup is Qualify, Develop, Approval, Close.  I am trying to figure out what field I need to sort by so that when I output with the line below that it matches how it's shown in setup.

    console.log('Get Process Stages: ', result.value);
  • Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: CRM Rest API - Get Processes with Stages ... can't find way to get Process Order

    Is it sorted Alphabetically descending?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans