Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM 365 how to add default text based on stage change.

(0) ShareShare
ReportReport
Posted on by 2

Hello All Experts,

I need to know do some default text to be added on the field.

can anyone help me.

I have one business process flow which has five different stages , having one common field on it.

i want to add default text based on Business Process Flow Stage Change, can anyone help me in resolving this with all the validations.

*This post is locked for comments

  • Verified answer
    Shahbaaz Ansari Profile Picture
    6,205 on at
    RE: CRM 365 how to add default text based on stage change.

    HI Octa,

    You can get the stage name and stage Id by that you can check condition for all your stages like below,

    f(stagename == "StageA")

    {

    Xrm.Page.getAttribute("field name").setValue("1");

    }

    else  if(stagename == "StageB")

    {

    Xrm.Page.getAttribute("field name").setValue("2");

    }

    else  if(stagename == "StageC")

    {

    Xrm.Page.getAttribute("field name").setValue("3");

    }

    else  if(stagename == "StageD")

    {

    Xrm.Page.getAttribute("field name").setValue("4");

    }

    else  if(stagename == "StageE")

    {

    Xrm.Page.getAttribute("field name").setValue("5");

    }

    Thanks,

    Shahbaaz

  • EmployeeOcta Profile Picture
    2 on at
    RE: CRM 365 how to add default text based on stage change.

    I am able to write down the business rule, but trouble is that at form load only for first time the Default value is getting set.

    but when i am clicking on the Next stage then nothing is happening only first stage value is remaining as it is.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: CRM 365 how to add default text based on stage change.

    Hi,

    You could take a look at the following article.

    Setting Field Values vs. Setting Default Values in Business Rules

    www.powerobjects.com/.../setting-field-values-vs-setting-default-values-business-rules

    Hope it helps.

    BR,

    Judy

  • EmployeeOcta Profile Picture
    2 on at
    RE: CRM 365 how to add default text based on stage change.

    Hello Michel van den,

    Your reply looks easy to implement , but now i want to know how to add multiple conditions in B.P.F to achieve the task.

    like i have 8 stages.

    for each stage selected i want to set the value.

  • Verified answer
    gdas Profile Picture
    50,089 Moderator on at
    RE: CRM 365 how to add default text based on stage change.

    Hi,

    You can refer below code.

    function onLoad() {

    Xrm.Page.data.process.addOnStageChange(getStage);

    getStage();

    }

    function getStage() {

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

    var stageId = activeStage.getId();

    var stageName = activeStage.getName();

    If (stageName=="stagename")

    {

    // don't forget to setsubmitmode = always for the field.

    //Set field value

    }

    }

    Hope this helps.

  • Verified answer
    Shahbaaz Ansari Profile Picture
    6,205 on at
    RE: CRM 365 how to add default text based on stage change.

    Hi Octa,

    You can put the onLoad funciton on page load and on change of stage you can set the value.

    You will get the stage name and you can check in if condition and set the value of the field, check below code

    function OnLoad() {

     // *** Whenever the stage changes trigger an onchange function

     Xrm.Page.data.process.addOnStageChange(stageOnChange);

     // To remove the function if required ….. Xrm.Page.data.process.removeOnStageChange(stageOnChange);

    }

    function stageOnChange() {

    var stagename = Xrm.Page.data.process.getActiveStage().getName();

    if(stagename == "StageA")

    {

    Xrm.Page.getAttribute("field name").setValue("1");

    }

    else  if(stagename == "StageA")

    {

    Xrm.Page.getAttribute("field name").setValue("2");

    }

    }

    Best Regards,

    Shahbaaz

  • Verified answer
    Michel van den Brink Profile Picture
    4,697 on at
    RE: CRM 365 how to add default text based on stage change.

    Hello,

    You could create a Business Rule that checks the condition whether your record is in a specific stage. Then if it is, you can use the 'Set Value' or the 'Set Default Value' action to set a field to a specific value.

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/customize/create-business-rules-recommendations-apply-logic-form 

      

    Alternativly, you can use the OnProcessStatusChange event to trigger client script (written in JavaScript) when your Business Process Flow changes stages.

    Using the addOnStageChange function you can register an event. The registration should be done on the load event of the form.

      

    Here's a quick example:

    // Associate this with the OnLoad event of the Form
    function OnFormLoad() { // Register the event Xrm.Page.data.process.addOnStageChange(function(e) { var args = e.getEventArgs();
    // If the stage is being moved forward if (args.getDirection() == 'next') {
    // Change the value of attribute with name 'my_attributename' Xrm.Page.getAttribute('my_attributename').setValue('My Default Value'); } }); }

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/formcontext-data-process/eventhandlers/addonprocessstatuschange

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/events/onstagechange 

  • Verified answer
    Community Member Profile Picture
    on at
    RE: CRM 365 how to add default text based on stage change.

    Hi,

    You can write javscript onchange of stage change.

    Please refer below.

    community.dynamics.com/.../javascript-add-code-on-business-process-flow-change-and-select

    Mansoor

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,863 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans