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
Thanks for sharing the outcome Jason, it helped me a lot!
Hi Jason,
That's great, glad you've got it sorted!
All the best
Alex
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
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.
I'm trying to achieve the same but struggling with the error message Unable to get property 'isRendered' of undefined or null reference
Thank you Mehrdad, that has worked. Much appreciated.
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
André Arnaud de Cal...
291,971
Super User 2025 Season 1
Martin Dráb
230,846
Most Valuable Professional
nmaenpaa
101,156