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)

Dynamics 365: switching UI business process flows from server-side

(2) ShareShare
ReportReport
Posted on by

Hello all,

We use Dynamics 365 Online. We have several business process flows for SalesOrder entity. And I want to switch processes on the server-side code.

On the client-side I can switch processes using setActiveProcess function. How to obtain the same on the server-side?

For Dynamics CRM 2016 I used SetProcessRequest to switch processes. Regarding Dynamics 365, I have noticed that this request creates new process instance, but it doesn't switch current UI process.

Please advise.

*This post is locked for comments

I have the same question (0)
  • C. Jensen Profile Picture
    384 on at

    Hi Dmitry

    If what you are trying to do is, activate another business process flow, at a specific stage, using the sdk, you should be able to use the following.

            private static void SwitchOpportunityProcess()
            {
                using (var srv = new Context(_service))
                {
                    var process = srv.WorkflowSet.Where(x => x.Name == "New Opportunity Business Process Flow").FirstOrDefault();
                    var stage = srv.ProcessStageSet.Where(x => x.ProcessId.Id == process.Id && x.StageCategory.Value == (int)processstage_category.Qualify).FirstOrDefault();
                    foreach (var opp in srv.OpportunitySet.Where(x => x.StateCode == OpportunityState.Open && x.ProcessId != process.Id && x.StageId != stage.Id).ToList())
                    {
                        Entity update = new Entity(opp.LogicalName, opp.Id);
                        update["processid"] = process.WorkflowId;
                        update["stageid"] = stage.ProcessStageId;
                        _service.Update(update);
                    }
                }
            }


  • Community Member Profile Picture
    on at

    Hi Christian,

    Thank you for your help. 

    I was able to switch processes via changing processid, stageid and traversedpath attributes for Dynamics CRM versions prior to 365.

    But now in 365, it only creates a new process instance record related to process where I want to switch to. UI process (that user currently see) stays the same.

  • C. Jensen Profile Picture
    384 on at

    Hi Dmitry

    1. Can the user switch the process manually? If not, it could be missing priviledge on the BPF.

    2. If you update the record from server-side code. Is the record actually updated, or does it keep the old values?

  • Community Member Profile Picture
    on at

    Christian,

    1. Yes, this user can switch processes manually. He is System Administrator.

    2. If I retrieve the record from the server-side code (_service.Retrieve), I see that the record is actually updated. Is has new process and new stage. But after refreshing browser's page, I see that process was not changed.

    So, I have two concurrent active business process flow instances. When I say business process flows instance, I mean a record on the new custom entity that represents my business process flow. I read about it here: msdn.microsoft.com/.../dn481586.aspx

  • ashlega Profile Picture
    34,477 on at

    Hi Dmitry,

     Might be a long shot, but did you confirm its not some sort of caching? When this problem happens, you might ask your user to open crm in the private browser mode, for example.

  • Community Member Profile Picture
    on at

    Hi Alex,

    Yes, I can confirm that it is not browser cache issue. I have refreshed browser's page using the Empty Cache and Hard Reload option (Chrome) and the process wasn't changed. I executed Xrm.Page.getAttribute("processid").getValue() and it showed me old process id value.

    But when I retrieve the same value from the server-side code, I see new process id (that I set earlier from the server-side code).

    It seems to me that client code retrieves value from the current UI BPF instance, but server side code doesn't know which active BPF instance is currently displayed on the UI. Therefore, it retrieves process id from the last created BPF instance. Just my thoughts.

  • C. Jensen Profile Picture
    384 on at

    Hi Dmitry

    You could try to abort the BPF, before activating the new one.

    In your code, start out by updating the record with processid and stageid set to null. After that, update the record with the new BPF.

  • ashlega Profile Picture
    34,477 on at

    Hi Dmitry,

     I tried SetProcessRequest on the server side just now, and, at least in my example, it seems to be working. I do have to reload the record (or use F5) on the client side to see the change, but, other than that, no side effects.

     Not sure how / if it helps - probably just some food for thought..

  • Community Member Profile Picture
    on at

    Hi Alex,

    Did you use Dynamics 365 in your example? SetProcessRequest worked fine for me when I used Dynamics CRM 2016 before concurrent BFSs were introduced.

  • Community Member Profile Picture
    on at

    Christian and Alex, thank you for your help.

    Finally, I have understood the reason of my issue. It seems that each user see his own BPF. It means if user A executes SetProcessRequest from the server-side to change BPF, it will be changed only for user A. User B stays at the old process. This is how concurrent BPFs work.

    But is there any way to change BPF for all users by single request?

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