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)

Setting the Default View on the Process Stage Bar with JavaScript

(0) ShareShare
ReportReport
Posted on by

Hi,

I have been trying to set the default view for a lookup field in the process stage header. From my research the code seems correct but I always result in:

"There was an error with this field's customized event... Error: Unable to get property 'setDefaultView' of undefined or null reference." 

The code should look like this: 

Xrm.Page.getControl(arg).getDefaultView()

Xrm.Page.getControl(arg).setDefaultView(viewGuid)
with my variables: 

var PRV = Xrm.Page.getControl("field_name").getDefaultView();
Xrm.Page.getControl("header_process_field_name").setDefaultView(PRV);

I have this calling on form load.


Can anyone make out what I could be doing wrong?

Thanks is advance!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Salutions,

    That lookup field in the Header Process flow only can be not undefined or exists in the HTML & your scripting when that field is available in the current stage.

    So, let's say you have 4 process stages -> A --> B --> C --> D

    Now, by default you are in stage A

    And then the lookup field you intended to set default view is in C, you cannot do that, the object is not yet called, so it will show Null that wont support .setDefaultView

    Since you use CRM 2015, the solution you can place this code in the BPF onStageChange event instead of form onload.

    Now in your form onload you need to add this one:

    Xrm.Page.data.process.addOnStageChange

    or

    Xrm.Page.data.process.addOnStageSelected

    And put the event handler that call your logic to set default

    msdn.microsoft.com/.../d88d5f21-6385-443b-91f2-0ec0c16b1324

    You also need to check the current process to get the C..

    Once users reach the process C, it will get the control and then you can set Default View

    To check the BPF scripts:

    msdn.microsoft.com/.../dn817874.aspx

    Hope this helps.

    Thanks.

  • Community Member Profile Picture
    on at

    Aileen Gusni - Thank you very much! Your detailed feedback allowed me to see my issue and understand it much better! I will work on completing the code with your instructions.

    Thank you again, it has been a great help to me!

    -SALutions

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