Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Consulting in the Actual Code.

Posted on by Microsoft Employee

Hello everybody!

I'll explain something of my BPM.

There are 6 Stages for "Selling" (Etapa -1 to Etapa-6)(Made with Dynamic CRM).

Also I've 2 Branch Stages for "Status"(Etapa -7 and Etapa -8)(Made with Dynamic CRM).

"Status" mean a conditional situation where the "Selling Process" go losting or freezing (On Hold) and only are avalible when user select "True" in "Lost" or "On Hold" (Conditional made with Bussines Process in Dynamic, not JS).

How "Status" are open with these options, I've made variables like number of selling status-1 (Because until Stage -5 we can get "Status" in the process). I mean for example: In Stage-1 I made mk_on_hold , in Stage-2 I made mk_on_hold_2,... The reason was because if all Status open with the same variable, in the process flow I'll look "Repeat Status" (S1-S8-S2-S8-S3-S8-.....).

With much help in the forum and somes investigation, I've made this code that can:

*Move automacticaly to Stage1-Stage2-Stage3-.......Stage6 when condictions are successed. Also it "refresh" the form, to look the actual active Stage. It mean that in Stage1 when conditions are true and you saved, it move to Stage2 and 1sec or 2 sec move the stagescreen to Stage2. Because if you use moveNext() alone, it only registed that Stage2 is the actual active stage, but your screen keep in Stage1 with a "Ticket or Flag" in Stage2 (Active advice).

* Move automacticaly the active from Stage8 (On Hold) to Stage1. But there I've a "problem".

-From Stage1 var (mk_on_hold): Actived Stage work perfectly, but don't change the screen (or refresh). I've tried put the same code that I used in moveNext() but it dont work.

-From Stage2 to 5 var (mk_on_hold_2 to 5): Actived Stage work "perfectly", I said it because it send an alert: dirtyForm and when I saved again, it send success and active Stage1.

PS: If you tried this code, you need know that it work with 2 saved, first saved data and second active "moves".

---------------------------------

Now here is where I need help with the follow ideas, because I don't know much of JS, I ask everytime jejeje:

1)Why the "movePrevious" from Stages2 to Stages5 send me "dirtyForm" and afther "Success"?

2)How I can fix (1)? Because I would like that it work in the second saved.

3)How I can "clear field" when come back? I mean, If I'm in Stage8-On Hold and the process get reactived, my idea was come back to Stage1. But in this process I would delete the value of "mk_on_hold_#" and "mk_reanudado_abandonado_#" because I think that if theses field keep their value, it will make problem to the process (don't know if movenext or moveprevious). I know that we have Xrm.page.getAttribute().setValue(); but it don't work to me (I put them before the movePrevious or setActiveStage().., because I think that frist must delete data and afther come back).

4) How I can "refresh" in the come back situation??

-----------------------------------

For your time and dedication, thanks you!

And please, don't answer me with the msdn page xD (the microsoft code page) :s they don't explain the codes. I work better if you show me a example or how write the code.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Consulting in the Actual Code.

    Ops I forgot the Script, I post there jajajajjaa

    ------------------

    function Move(){

    // Definir Booleano respecto a moveToNext

    var moveToNext = true;

    // Para adquirir información del Stage activo del proceso.

    var activeStage = Xrm.Page.data.process.getActiveStage();

    // Para adquirir la colección de Stages del proceso.

    var activePathCollection = Xrm.Page.data.process.getActivePath();

    // Para adquirir el Stage actual

    var StageSelect = Xrm.Page.data.process.getSelectedStage();

    //Para adquirir el nombre del Stage actual

    var StageName = StageSelect.getName();

    //debugger;

    // Condicionemos el proceso para fase 1-5

    if (StageName === "Etapa 1- Identificar Prospecto"){

    var backstage = Xrm.Page.data.process.getSelectedStage();

    var manic = Xrm.Page.getAttribute("mk_manact_inicial").getValue();

    var reuini = Xrm.Page.getAttribute("mk_reunion_inicial").getValue();

    if((manic == false) ||(reuini == false) ){

    moveToNext = false;

    }

    if (moveToNext) {

       //Move to the next stage y VISTA

     Xrm.Page.data.process.moveNext(function (status)

    {

    console.log(status);

    console.log(Xrm.Page.ui.getFormType());

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

    function successCallback()

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    function errorCallback()

    {

    console.log("error");

    }

    }

    else if (status == "success")

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    });

    }

    }

    if (StageName === "Etapa 2- Reconocer Necesidades"){

    var backstage = Xrm.Page.data.process.getSelectedStage();

    var manac =  Xrm.Page.getAttribute("mk_manact_actualizado").getValue();

    var whois =  Xrm.Page.getAttribute("mk_who_is_who").getValue();

    var cust =  Xrm.Page.getAttribute("mk_customer_need").getValue();

    var spin =  Xrm.Page.getAttribute("mk_spin").getValue();

    if (( manac == false) || (whois == null) || (cust == null) || (spin == false)){

    moveToNext=false;

    }

    if (moveToNext) {

       //Move to the next stage y VISTA

         Xrm.Page.data.process.moveNext(function (status)

    {

    console.log(status);

    console.log(Xrm.Page.ui.getFormType());

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

    function successCallback()

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    function errorCallback()

    {

    console.log("error");

    }

    }

    else if (status == "success")

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    });

    }

    }

    if (StageName === "Etapa 3- Evaluar Alternativa"){

    var backstage = Xrm.Page.data.process.getSelectedStage();

    var ppremi =  Xrm.Page.getAttribute("mk_propuesta_premilinar").getValue();

    var vulne =  Xrm.Page.getAttribute("mk_vulnerabilidad").getValue();

    var currents =  Xrm.Page.getAttribute("mk_current_situation").getValue();

    if ((ppremi == false) || (vulne == false) || ( currents == null)){ moveToNext=false;

    }

    if (moveToNext) {

       //Move to the next stage y VISTA

        Xrm.Page.data.process.moveNext(function (status)

    {

    console.log(status);

    console.log(Xrm.Page.ui.getFormType());

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

    function successCallback()

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    function errorCallback()

    {

    console.log("error");

    }

    }

    else if (status == "success")

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    });

    }

    }

    if (StageName === "Etapa 4- Resolución De Aprensiones"){

    var backstage = Xrm.Page.data.process.getSelectedStage();

    var iapre =  Xrm.Page.getAttribute("mk_iaprensiones").getValue();

    var fechaec =  Xrm.Page.getAttribute("mk_estimated_close_date").getValue();

    var rapre =  Xrm.Page.getAttribute("mk_raprensiones").getValue();

    if ((rapre == false) || (fechaec == null) || ( iapre == null)){ moveToNext=false;

    }

    if (moveToNext) {

       //Move to the next stage y VISTA

         Xrm.Page.data.process.moveNext(function (status)

    {

    console.log(status);

    console.log(Xrm.Page.ui.getFormType());

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

    function successCallback()

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    function errorCallback()

    {

    console.log("error");

    }

    }

    else if (status == "success")

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    });

    }

    }

    if (StageName === "Etapa 5- Negociación"){

    var backstage = Xrm.Page.data.process.getSelectedStage();

    var pfa =  Xrm.Page.getAttribute("mk_propuestafinaladjuntado").getValue();

    if ((pfa == false) ){ moveToNext=false;

    }

    if (moveToNext) {

       //Move to the next stage y VISTA

        Xrm.Page.data.process.moveNext(function (status)

    {

    console.log(status);

    console.log(Xrm.Page.ui.getFormType());

    if (Xrm.Page.ui.getFormType() == 1 && status == "invalid")

    {

    Xrm.Page.data.entity.save().then(successCallback, errorCallback);

    function successCallback()

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    function errorCallback()

    {

    console.log("error");

    }

    }

    else if (status == "success")

    {

    Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());

    }

    });

    }

    }

    // Estado1 = Renudar Proceso --> Volver a Etapa 1, el cual es el primero por lógica en ser activo.

    if ( Xrm.Page.getAttribute("mk_reanudar_abandonar").getValue() == 850000000){

    Xrm.Page.data.process.movePrevious();

    }

    // Estado2 = Renudar Proceso --> Volver a Etapa 1, el cual es el primero por lógica en ser activo.

    if ( Xrm.Page.getAttribute("mk_reanudar_abandonar_2").getValue() == 850000000){

      Xrm.Page.data.process.setActiveStage("8fe9029a-e925-4224-97eb-f6603847a95b", function (estado) { Xrm.Utility.alertDialog(estado, null);})

    }

    // Estado3 = Renudar Proceso --> Volver a Etapa 1, el cual es el primero por lógica en ser activo.

    if ( Xrm.Page.getAttribute("mk_reanudar_abandonar_3").getValue() == 850000000){

      Xrm.Page.data.process.setActiveStage("8fe9029a-e925-4224-97eb-f6603847a95b", function (estado) { Xrm.Utility.alertDialog(estado, null);})

    }

    // Estado4 = Renudar Proceso --> Volver a Etapa 1, el cual es el primero por lógica en ser activo.

    if ( Xrm.Page.getAttribute("mk_reanudar_abandonar_4").getValue() == 850000000){

    Xrm.Page.data.process.setActiveStage("8fe9029a-e925-4224-97eb-f6603847a95b", function (estado) { Xrm.Utility.alertDialog(estado, null);})

    }

    // Estado5 = Renudar Proceso --> Volver a Etapa 1, el cual es el primero por lógica en ser activo.

    if ( Xrm.Page.getAttribute("mk_reanudar_abandonar_5").getValue() == 850000000){

      Xrm.Page.data.process.setActiveStage("8fe9029a-e925-4224-97eb-f6603847a95b", function (estado) { Xrm.Utility.alertDialog(estado, null);})

    }

    }

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans