Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Populate default business process flow onload form

Posted on by 353
Hello,
 
in Sales Hub app, Lead entity with a main form: SalesHub-Lead. There are two Lead BPFs in this app: SalesHub- Lead to Opportunity Process (Custom) and Lead to Opportunity Process (System).
 
Requirement: Opening SalesHub-Lead form always display the  SalesHub-Lead to Opportunity Process. My script as below:
 
//====================================================
 
function onLoadSetDefaultBPF(executionContext) {
 
    debugger;
 
    var formContext = executionContext.getFormContext();
 
    var activeProcessName = formContext.data.process.getActiveProcess().getName();
 
    if (activeProcessName == null || activeProcessName !== 'SalesHub - Lead to Opportunity Process') {
 
        var parameters = {};
 
        parameters['process'] = 'SalesHub - Lead to Opportunity Process';
       
        Xrm.Navigation.openForm(/lead/, null, parameters);
    }
}
 
//===================================================
 
Implemented webresource  in SaleHub-Lead form, it's not working. The error message:
 
One of the scripts for this record has caused an error. For more details, download the log file.

Cannot read properties of null (reading 'getName')
Session Id: 3325fc28-9410-45cd-80e4-
Correlation Id: 73e0c609-e108-4194-aaee-
Event Name: onload
Function Name: onLoadSetDefaultBPF
Web Resource Name: SaleHub_lead_setdefaultBPFbasedonapp.js
Solution Name: Active
 
 
Could you please help to check what problem I have made?
 
Thanks!
  • Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Populate default business process flow onload form
    Hi,
     
    Please check if there is an active BPF in the current entity, if not the value obtained via the getActiveProcess() method is null.
     
    Best Regards,
    Dengliang Li
     
  • Inogic Profile Picture
    Inogic 24,094 on at
    Populate default business process flow onload form
    Hi,

    If you want to display the custom BPF process then check the below code –

    setDefaultBPFForOpportunity = function (executionContext) {
                var functionName = "onChange ";
                var formContext;
                var quantity;
                var pricePerUnit;
               
                    if (CRM_BPFLib.isValid(executionContext) && CRM_BPFLib.isValid(executionContext.getFormContext)) {
                        formContext = executionContext.getFormContext();
                        var activeProcessID = formContext.data.process.getActiveProcess().getId();
                        if (formContext != null) {
                            formContext.data.process.setActiveProcess("3E8EBEE6-A2BC-4451-9C5F-B146B085413A", CRM_BPFLib.callBackFunction);
                        }
                    }
                    ;
               
            };
    callBackFunction = function (result) {
                if (result == "success") { }
                else { }
            };

    Add your process ID in the ‘setActiveProcess’ method.


    Hope this helps.
     
    Thanks!

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans