Skip Setting a Business process flow during record create in Dynamics 365/ CDS? This simple trick may help you

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com

We all love Business Process flows. And why not? Their introduction have solved the age old problem of visualizing a record as and when it progress through multiple stages. Typically lead and opportunity moving through multiple stages, a product moving through multiple stages of development and numerous other examples can be cited.

And yet there can be scenarios where you need to skip applying business process when the record is created. Typical example may be bulk importing records from some other sources where you are not sure about what business process need to be applied and you want the decision to be left to end-users when they work with the respective records. Really there can be scenarios which you never thought.

I've never thought about it like that before | Honest about my faith

In scenarios like this, how do you plan to do the same. After all the default business process flow configured for an entity is automatically applied when you create new record for the entity.

We know for every entity there is a field called ProcessId. You may be wondering, isn’t it deprecated. Yes it is deprecated. However as much surprising it is, the same will come to help in scenarios like this.

All we need to do in this case is set the ProcessId field to Guid.Empty. That’s all.

And how are you going to do it. Well there can be many ways but in our scenario if it is bulk import, we can have a plugin in pre-operation stage where we will set the value of ProcessId to Guid.Empty.

Something like this shall work.

public class SetProcessIdToBlank : IPlugin
    {
       public void Execute(IServiceProvider serviceProvider)
       {
          var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
          var target = (Entity)context.InputParameters["Target"];

         target["processid"] = Guid.Empty;
       }
    }

And now the records shall be created without any Business process flow record.

Hope this helps!

Debajit Dutta

(Microsoft MVP)

Designing Business process flows for your canvas apps

I had this requirement lately and the first time I heard this I thought, is this even possible? But then I never doubt about the every increasing capability of canvas apps. So decided to do a search.

And guess what! Found this wonderful documentation here with a complete solution.

Advertisements

https://powerapps.microsoft.com/en-us/blog/using-business-process-flows-in-a-canvas-app/

I am simply falling in love with PowerApps documentation which is so much focused on implementation and solutions rather than just theory.

Towards the end of the solution, you will find a link to download the powerapps solution sample. Link – https://github.com/microsoft/powerapps-tools/blob/master/Apps/BusinessProcessFlow/BPF_Solution_1_0_0_11.zip

Advertisements

One point to note here – The BPF Component shown in the blog is not an OOB control available but in fact it is a generic control custom built for designing a BPF. So if you are searching a control with that name in your powerapps component list, you may not get it.

Hope this small tip helps!

Debajit Dutta

Business solutions MVP

Control Next and Previous stage movement in Dynamics 365/ CDS Business Process flows using Client API

Honestly I was not aware of this function sometime back and this was purely an accidental discovery. And guess what when I queried around, I found that it actually missed the cognizance of so many consultants out there. And while this function have been introduced, we still keep telling the customer that it is kind of not possible to show something like a user confirmation before stage movement.

You may argue that “OnStageChange” event has been there from the beginning. However the issue with it is, it fires when the stage have already changed. Hence does not make any sense.

In the below example I am going to show you couple of scenarios. And trust me if you are not aware of this and seeing for the first time, it will be a huge sense of relief for you since this is a kind of requirement which pops up every now and then.

  • Getting user confirmation before the stage movement happens
  • Stop back stage movement.

Below is the sample code that I have set up for account entity form


var Acc = {};
Acc.formEvents = {
    stageMovementConfirmed: false,





   form_load: function (e) {
       var fc = e.getFormContext();                    
       fc.data.process.removeOnPreStageChange(Acc.formEvents.handlePreStage);
       fc.data.process.addOnPreStageChange(Acc.formEvents.handlePreStage);
    },





   handlePreStage: function (e) {
       debugger;





     // get the event arguments
       var bpfArgs = e.getEventArgs();





      if (bpfArgs.getDirection() === "Previous") // back stage movement is not allowed;
       {
          bpfArgs.preventDefault();
          var alertStrings = { confirmButtonLabel: "OK", text: "Back stage movement is not allowed", title: "Sample title" };
          var alertOptions = { height: 120, width: 260 };
          Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
          return;
       }





      // this will fire again when move next is called.
       // so if stage movement has been allowed earlier, please proceed. else ask for user confirmation.

       if (Acc.formEvents.stageMovementConfirmed === true) {
          Acc.formEvents.stageMovementConfirmed = false;
          return;
       }





      if (bpfArgs.getDirection() === "Next") { // only next stage movement is allowed.




         // stop the stage movement
          bpfArgs.preventDefault();





         var confirmStrings = { text: "Are you sure you want to move to the next stage?", title: "Stage movement Confirmation!" };
          var confirmOptions = { height: 150, width: 300 };
          Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
             function (success) {
                if (success.confirmed) {
                   Acc.formEvents.stageMovementConfirmed = true;
                   e.getFormContext().data.process.moveNext();
                }
             });
       }





      // you can also play with the other properties of eventargs
       // get the stage - bpfArgs.getStage();
       // get the steps - bpfArgs.getStage().getSteps();





   }
};

Well, it’s a very simple code. The form_load event is fired on account form load and registers the function handlePreStage on Business process “onPreStageChange” event.

The remaining part is self explanatory and I have basically put all the code with appropriate comments to highlight what all you can do with this function.

All set and done, below is the experience I get when I try this out.

Hope you find this quite interesting!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/2019/02/28/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)