Tuesday 11 October 2016

MSCRM 2015, 2016 Business Process Flow Stage Change Automatically Using JavaScript

Hi this is Sudhakar Reddy Chidipudi

Description:

1.         Business process flows to define a set of steps for people to follow to take them to a desired outcome.
2.       These steps provide a visual indicator that tells people where they are in the business process.
In real time scenarios BPF should be moved from one stage to another stage automatically .Below JavaScript does the same.

function moveNextStage(stgName, flowStatus)
{
                try
                {
                                var pollingAttemptsRemaining = 10;
                                var intervalId;
                                intervalId = setInterval(function ()
                                {
                                                pollingAttemptsRemaining -= 1;
                                                if (Xrm.Page.data.process.getActiveStage().getName() != stgName)
                                                {
                                                                clearInterval(intervalId);
                                                }
                                                if (!Xrm.Page.data.entity.getIsDirty() && Xrm.Page.data.process.getActiveStage().getName() == stgName)
                                                {
                                                                if (flowStatus)
                                                                {
                                                                                Xrm.Page.data.process.moveNext(moveResult);
                                                                }
                                                                else
                                                                {
                                                                                Xrm.Page.data.process.movePrevious(moveResult);
                                                                }
                                                                pollingAttemptsRemaining = 0;
                                                                clearInterval(intervalId);
                                                }
                                                if (pollingAttemptsRemaining <= 0)
                                                {
                                                                clearInterval(intervalId);
                                                }
                                }, 200);
                }
                catch (err)
                {
                                Xrm.Page.ui.setFormNotification("Error occured in function : moveNextStage()" + ".Details : " + (e.description || e.message), "ERROR");
                }
}
function moveResult(result)
{}

How to call above function? Use below code
moveNextStage(“Your BPF stage name”, true); //true moves stage forward  .


Have a nice day ............................... :)

Thursday 30 June 2016

MSCRM 2015, 2016 Business Process Flow Stage Change Automatically Using JavaScript

Hi this is Sudhakar Reddy Chidipudi

In real time scenarios BPF should be moved from one stage to another stage automatically .
Below JavaScript does the same.

function moveNextStage(stgName, flowStatus)
{
try
{
var pollingAttemptsRemaining = 10;
var intervalId;
intervalId = setInterval(function ()
{
pollingAttemptsRemaining -= 1;
if (Xrm.Page.data.process.getActiveStage().getName() != stgName)
{
clearInterval(intervalId);
}
if (!Xrm.Page.data.entity.getIsDirty() && Xrm.Page.data.process.getActiveStage().getName() == stgName)
{
if (flowStatus)
{
Xrm.Page.data.process.moveNext(moveResult);
}
else
{
Xrm.Page.data.process.movePrevious(moveResult);
}
pollingAttemptsRemaining = 0;
clearInterval(intervalId);
}
if (pollingAttemptsRemaining <= 0)
{
clearInterval(intervalId);
}
}, 200);
}
catch (err)
{
Xrm.Page.ui.setFormNotification("Error occured in function : moveNextStage()" + ".Details : " + (e.description || e.message), "ERROR");
}
}

function moveResult(result)
{}

How to call above function? Use below code
moveNextStage(“Your BPF stage name”, true); //true moves stage forward  .


Have a nice day ............................... :)