Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting Default BPF in case record through Scripting error

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I have two forms in the case record and 2 separate BPF to be applied.

BPF 1 is already applied on both forms.

I would like to apply BPF 2 to form 2 and I'm using the following code onLoad but its showing script error.

function setDefaultBPF() {  
    var formId = '3d6a3fccfa-8415-47d2-a4e2-6a94cda3599c';     
    var businessProcessId = '7bF9000D1B-A393-4BBF-AD31-7678A1EBA056';     
    var entityName = 'incident';  
    var FORM_TYPE_CREATE = 1;     
    var queryStringParams = Xrm.Page.context.getQueryStringParameters();
  if (Xrm.Page.ui.getFormType() == FORM_TYPE_CREATE &&  (queryStringParams.process == null || queryStringParams.process != businessProcessId)) {  
      var parameters = {}; 
      parameters["formid"] = formId; 
      parameters["process"] = businessProcessId;
            // this will open new Opportunity form with default BPF as specified                            
    Xrm.Utility.openEntityForm(entityName, null, parameters);   
    } 
}



Is there any mistake in the code?

Thanks,

Jon

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Goutam,

    I'm not getting any error but still the default BPF seems to be loading.

    Thanks,

    Purvesh

  • gdas Profile Picture
    50,091 Moderator on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Jon ,

    What error you are getting ?  its should work try to use second one which I have shared .

  • Community Member Profile Picture
    on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Shidin,

    I'm using Dynamics 365 v9.

    Thanks,

    Jon

  • Community Member Profile Picture
    on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Goutam,

    Thank you for your reply.

    I tried both codes you provided but they are not working. I am not getting any script error but it's just not showing the required BPF.

    I rechecked my my formID and processID using the decoding tool on tutorialsright.com.

    Thanks,

    Jon

  • Suggested answer
    Shidin Haridas Profile Picture
    3,497 on at
    RE: Setting Default BPF in case record through Scripting error

    Which version of CRM are you working with?

    CRM 2016 and onwards have the concept of concurrent BPFs, which pretty much means that there is no use setting the 'processid' and 'stageid' fields.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Jon ,

    There is some issue with the if statement . I found the  queryStringParams.process getting undefined so you don't need to check that processid. Secondly please check the formid and BPF id is correct.

    Here is the code will work fine for you -

            function setDefaultBPF() {
                var formId = '3d6a3fccfa-8415-47d2-a4e2-6a94cda3599c';
                var businessProcessId = '7bF9000D1B-A393-4BBF-AD31-7678A1EBA056';
                var entityName = 'incident';
                var FORM_TYPE_CREATE = 1;
                var queryStringParams = Xrm.Page.context.getQueryStringParameters();
                          
                if ((Xrm.Page.ui.getFormType() == FORM_TYPE_CREATE)) {
                    var parameters = {};
                    parameters["formid"] = formId;
                    parameters["process"] = businessProcessId;
                    // this will open new Opportunity form with default BPF as specified            
                    if (queryStringParams.process != undefined && queryStringParams.process != null) {  
                        if (queryStringParams.process != businessProcessId) {                       
                            Xrm.Utility.openEntityForm(entityName, null, parameters);
                        }
                    }
                    else {         
                        Xrm.Utility.openEntityForm(entityName, null, parameters);
                    }
                }
            }


    You can also write without check process id as  you does not get process id in the query string..

            function setDefaultBPF() {
                var formId = '3d6a3fccfa-8415-47d2-a4e2-6a94cda3599c';
                var businessProcessId = '7bF9000D1B-A393-4BBF-AD31-7678A1EBA056';
                var entityName = 'incident';
                var FORM_TYPE_CREATE = 1;         
                if ((Xrm.Page.ui.getFormType() == FORM_TYPE_CREATE)) {
                    var parameters = {};
                    parameters["formid"] = formId;
                    parameters["process"] = businessProcessId;
                    // this will open new Opportunity form with default BPF as specified            
                   
                        Xrm.Utility.openEntityForm(entityName, null, parameters);
                    }
                }

    Hope this helps.

  • Aman Anvaria Profile Picture
    306 on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Jon,

    Please check your business process Id and form Id.

    Thanks & Regards,

    Aman Anvaria

  • Aman Anvaria Profile Picture
    306 on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Jon,

    Can you please share script-error?

    Thanks & Regards,

    Aman Anvaria

  • Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Setting Default BPF in case record through Scripting error

    Hi Jon,

    can you try to debug the JS?

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans