zoukankan      html  css  js  c++  java
  • Control Next and Previous stage movement in Dynamics 365/ CDS Business Process flows using Client API / PowerApps

     

    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, 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, 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.

  • 相关阅读:
    RESTful API 设计指南【转】
    一款 .NET 下的轻量级 REST 和 HTTP API 客户端
    Windows 服务开发框架介绍
    实例演示 kino.razor (前端 Javascript 模板工具,Razor 风格)的使用
    深入研究 蒋金楠(Artech)老师的 MiniMvc(迷你 MVC),看看 MVC 内部到底是如何运行的
    扩展 IEnumerable<T>,让它根据另一个集合的顺序来排列
    谷歌正式发布Google APIs Client Library for .NET
    身为码农,为12306说两句公道话
    12306外包给阿里巴巴/IBM到底是否可行?
    自定义一个叫 ReadOnlyXmlMembershipProvider 的 MembershipProvider,用 XML 作为用户储藏室
  • 原文地址:https://www.cnblogs.com/lingdanglfw/p/15068729.html
Copyright © 2011-2022 走看看