web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Business Process Flow - Move to next stage after first save

(0) ShareShare
ReportReport
Posted on by 11,323

Hi,

I'm currently trying to force the business process to move to the next stage if the user saves. This works when the record already exists aka updating the form, but I cant seem to get it to work when the record is new aka creating a record. 

I'm currently trying to save the record first, then wait for the success callback then I will use the openEntityForm(). But it doesn't seem to work.

Any Ideas?

function moveNextStage()
{
	var activeProcess = Xrm.Page.data.process.getActiveProcess();
	if (activeProcess != null)
	{
		var process = Xrm.Page.data.process.getActiveProcess().getName();
		if (process == "Case - Sales Process")
		{
			var stage = Xrm.Page.data.process.getActiveStage().getName();
			if (stage == "Activity")
			{
				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());
					}
				});
			}
		}
	}
}

*This post is locked for comments

I have the same question (0)
  • Ahmad Saud Profile Picture
    790 on at
    RE: Business Process Flow - Move to next stage after first save

    Thanks Thomas.

  • Thomas David Dayman Profile Picture
    11,323 on at
    RE: Business Process Flow - Move to next stage after first save

    Hi Ahmad,

    I believe that its onSave

  • Ahmad Saud Profile Picture
    790 on at
    RE: Business Process Flow - Move to next stage after first save

    Hi Ben

    how to use this code? i have the same problem.

    I assume i shall use JS-webresource, but what is the event i need to use. please help me.

  • Ahmad Saud Profile Picture
    790 on at
    RE: Business Process Flow - Move to next stage after first save

    Hi Thomas

    how to use this code? i have the same problem.

    I assume i shall use JS-webresource, but what is the event i need to use. please help me.

  • Ben Salins Profile Picture
    110 on at
    RE: Business Process Flow - Move to next stage after first save

    If ever there was a Nobel Prize for manipulating Business Process in XRM, you would be getting it for sure.

    Thanks a lot mate, this code helped me get my code working.

    I nearly gave up manipulating my business process, till I found this gem.

    thanks again.

    -ben

  • Verified answer
    Thomas David Dayman Profile Picture
    11,323 on at
    RE: Business Process Flow - Move to next stage after first save

    If anyone finds is interested.

    This is the solution:

    The 2 functions below the 'moveNextStage' will wait until the form is saved and then you can execute your code.

    function moveNextStage()
    {
    	var activeProcess = Xrm.Page.data.process.getActiveProcess();
    	if (activeProcess != null)
    	{
    		var process = Xrm.Page.data.process.getActiveProcess().getName();
    		if (process == "Case - Sales Process")
    		{
    			var stage = Xrm.Page.data.process.getActiveStage().getName();
    			if (stage == "Activity")
    			{
    				Xrm.Page.data.process.moveNext(function (status)
    				{
    					console.log(status);
    					console.log(Xrm.Page.ui.getFormType());
    					if (status == "success")
    					{
    						Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
    					}
    				});
    			}
    		}
    	}
    }
    
    function ExecuteWhenSaveComplete(callback)
    {
    	setTimeout(function ()
    	{
    		if (!Xrm.Page.data.entity.getIsDirty()) return callback();
    		//console.log('form not saved yet');
    		ExecuteWhenSaveComplete(callback);
    	}, 500);
    }
    
    function SetExecuteOnSaveComplete()
    {
    	ExecuteWhenSaveComplete(function ()
    	{
    		console.log('form save complete');
    		moveNextStage();
    	});
    }


  • Gopalan Bhuvanesh Profile Picture
    11,401 on at
    RE: Business Process Flow - Move to next stage after first save

    Hi

    Please check the constraints for Xrm.Page.data.process.moveNext

    This method can only be used when the selected stage and the active stage are the same

    Refer:

    msdn.microsoft.com/.../dn817878.aspx

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans