web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Arun Vinoth Profile Picture
    11,615 Moderator on at

    Is it sorted Alphabetically descending?

  • Community Member Profile Picture
    on at

    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);
  • Community Member Profile Picture
    on at

    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.

  • Suggested answer
    Macoy Profile Picture
    275 on at

    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
    on at

    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"


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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans