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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript help to check if Business Process Flow exists on the form

(0) ShareShare
ReportReport
Posted on by 422

Hi,

Please note my CRM version: 2015 On-premises update 0.1

Given the version of CRM I have here I only have the Xrm.Page.ui.process methods of set visible and set display state. 

I have 2 different case types in CRM and for one of them I want to always hide the BPF and the other always show. 

I have successfully used JavaScript and the setVisible method to achieve this for most scenarios.

Unfortunately I have a lot of resolved cases which came over from CRM2011 and as such do not have any reference to the BPF on the form and I get this error when viewing the resolved case record "Unable to get property 'setVisible' of undefined or null reference". 

Ideally my JavaScript would say: Does a BPF exists on the form? If Yes, check the type then set visible true or false.

I have tried methods such as Xrm.Page.data.process.getActiveProcess() and Xrm.Page.data.process.getEnabledProcesses() to try and return a null value but I get the same error message as above on load.

A workaround is to re-open then close the cases but this is not very feasible due to volume.

Any suggestions appreciated. Thanks.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    MehrCrm Profile Picture
    290 on at

    Hi,

    Please try the following.

    if(Xrm.Page.data.process) {
    	var activeProcess = Xrm.Page.data.process.getActiveProcess();
    	if(activeProcess && activeProcess.isRendered()) {
    		// BPF exists on the form
    		// Do something
    	} else {
    		// No BPF exists
    	}
    } else {
    	// No BPF exists
    }


    Hope this helps,

    Mehrdad

  • AlexJay Profile Picture
    422 on at

    Thank you Mehrdad, that has worked. Much appreciated.

  • JasonMcandrew Profile Picture
    40 on at

    I'm trying to achieve the same but struggling with the error message Unable to get property 'isRendered' of undefined or null reference

    My script works if the record has a process running but the error above occurs if the process has not been started.
    Do you have an example of how you implemented this?
    Thanks
    Jason
  • AlexJay Profile Picture
    422 on at

    Hi Jason, 

    In case it helps this is the full code snippet I used:

    function showHideProcessFlow(){
    var caseType = Xrm.Page.getAttribute("casetypecode").getText(); // Get Case Type
    var stateCode = Xrm.Page.getAttribute("statecode").getValue(); // Get Status
    if(Xrm.Page.data.process) {
    var activeProcess = Xrm.Page.data.process.getActiveProcess();
    if(activeProcess && activeProcess.isRendered()) {
    if (caseType == "Customer Support"){
    Xrm.Page.ui.process.setVisible(false);
    }
    else if (caseType == "Code of Conduct"){
    Xrm.Page.ui.process.setVisible(true);
    }
    } else {
    // No BPF exists
    }
    } else {
    // No BPF exists
    }
    }

    Was a while ago so perhaps much has changed. Such as using formContext instead of XRM.Page

    Sounds like the Xrm.Page.data.process.getActiveProcess() call is returning null or undefined when looking for any active processes in one of your scenarios.  Perhaps you could incorporate an additional null check on that in order to not run into your error, something like if(activeProcess == null) should check for whether it's undefined or null. I'm not a developer though so not the best person to be giving javascript advice! Hopefully someone else can chip in. 

    Best wishes, Alex. 

  • JasonMcandrew Profile Picture
    40 on at

    Hi Alex,

    Thankyou for replying, your code snippet was very helpful.

    My original stab at this wasn't far off, i was missing and additional if statement.

    This is what i ended up with and it's working perfectly to collapse the process flow if it exists on the form or do nothing if a process flow doesn't exist.

    function Collapsebpf(executionContext)

    {

    var formContext = executionContext.getFormContext();

    if(formContext.data.process) {

    var activeProcess = formContext.data.process.getActiveProcess();

    if(activeProcess && activeProcess.isRendered()) {

    var displayState = formContext.ui.process.getDisplayState();

    if (displayState == "expanded")

    {

    formContext.ui.process.setDisplayState("collapsed");

    }

    else if (displayState == "collapsed")

    {

    formContext.ui.process.setDisplayState("collapsed")

    }

    }

    else {

    // No BPF exists

    }

    }

    }

    Many thanks

    Jason

  • AlexJay Profile Picture
    422 on at

    Hi Jason,

    That's great, glad you've got it sorted!

    All the best

    Alex

  • Erik Schaap Profile Picture
    25 on at

    Thanks for sharing the outcome Jason, it helped me a lot!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans