In Dynamics 365 CRM, sometimes you want to hide and show tab according to some conditions. We will see how to show and hide tab while using fields.
In this example, we will show the tab ‘Tick‘ when user puts value in ‘Material Description‘ otherwise the tab will be hidden. Let’s see how to achieve this through JavaScript.
This is the end result we are expecting.
Add JavaScript Web Resource
Go to Advance Settings -> Settings -> Customization (Go to Customize the System OR inside the solution you made) -> Web Resources -> Click on ‘New’.
Below window will open.
Give any meaningful display name like ‘HideShowOnTick’.
Next, in the Content section, select Type ‘Script (JScript)’.
Select Language as English. Now you can click on Save.
Open ‘Text Editor’ next to Type and put below JavaScript code.
function HideOrShow(executionContext) {
const formContext = executionContext.getFormContext();
let materialdescriptions = formContext.getAttribute(“crmonce_materialdescription”).getValue();
if (materialdescriptions == true) {
formContext.ui.tabs.get(“Tick”).setVisible(true); //Shows Tab
} else {
formContext.ui.tabs.get(“Tick”).setVisible(false); //Hide Tab
}
}
In above JavaScript code, name of attribute and tab should be correct. Go to tab properties and check exact tab name and put the same in the Code. Similarly, go to the Material Description field’s change properties and pick up the name from there.
Link Web Resource to ‘Ticker Symbol’ Field Properties
Entities -> Sales and Service -> Forms -> Service (Main Form).
Open Form.
Select Material Description field. Double click on it OR select and click on ‘Change Properties’. You will get window as below.
Inside Events Tab, expand Form Libraries. Click on Add Button. You will get below pop up.
In the Search box, You need to search for your Web Resource. Search only works on Name field. So in search box, just put initials of resource display name or with schema name. In the above image you could see that I have just typed *crmonce to search resource.
Select resource you get that in the list and click on add button.
Now, in the Event Handlers section, click on Add button.
OnChange is the only event you will find selected. After clicking on Add you will get below pop-up.
Select your Web Resource from library and in the Function textbox write your JavaScript function name. In this example it is ‘Material Description’.Select your Web Resource from library and in the Function textbox write your JavaScript function name. In this example it is ‘HideorShow’.we need Pass execution context as first parameter. Click On OK.
Function should be added to properties window. Click OK on Properties window. Click On OK.
Now, Click on ‘Form Properties’.
You need to add ‘Web Resource’ similarly you did for Field Properties. After Adding, come to Event Handlers section. Select values for Control – Form & Event – OnLoad.
Now click on Add button to add Function (Similar to Field Properties you did). See below.
we need Pass execution context as first parameter
Click on OK.
Finally, you need to Save and Publish Changes.
Note: Without publishing changes won’t reflect on UI.
We are done with the changes. Now, you can go to the UI and in one of the Sales and Service. Try to add and remove value in ‘Material Description’ field and check if ‘Tick’ Tab is showing and hiding properly or not. Also, Save the form and check if the tab’s current state persists or not.
CASE 1: No Value in ‘Ticker Symbol’. ‘Scheduling’ Tab is not visible.
CASE 2: Value is in ‘Ticker Symbol’. ‘Scheduling’ Tab should be Visible.
CASE 3: Save the record WITH value in ‘Ticker Symbol’ and load the page (press F5). ‘Scheduling’ tab SHOULD be visible.
(Perform this yourself and check results)
CASE 4: Save the record WITHOUT value in ‘Ticker Symbol’ and load the page (press F5). ‘Scheduling’ tab SHOULD NOT be visible.
(Perform this yourself and check results)
This is how we can achieve showing and hiding tabs functionality by using JavaScript in Dynamics 365 CRM.
I would like to thank you for the efforts youve put in penning this website. I really hope to check out the same high-grade content by you later on as well. In truth, your creative writing abilities has encouraged me to get my own website now 😉
Thank you so much for your valuable feedback.
An attention-grabbing dialogue is price comment. I believe that you must write more on this subject, it won’t be a taboo topic but generally people are not enough to speak on such topics. To the next. Cheers
An added important area is that if you are an older person, travel insurance with regard to pensioners is something that is important to really consider. The older you are, the more at risk you happen to be for permitting something undesirable happen to you while in foreign countries. If you are not covered by many comprehensive insurance policy, you could have many serious challenges. Thanks for expressing your guidelines on this web site.
Youre so cool! I dont suppose Ive read something like this before. So good to search out any individual with some unique ideas on this subject. realy thanks for starting this up. this web site is something that’s wanted on the internet, someone with just a little originality. useful job for bringing something new to the internet!
I?m impressed, I need to say. Actually hardly ever do I encounter a blog that?s each educative and entertaining, and let me inform you, you have hit the nail on the head. Your concept is outstanding; the difficulty is one thing that not enough individuals are speaking intelligently about. I am very pleased that I stumbled across this in my search for something regarding this.
great issues altogether, you just received a new reader. What would you recommend in regards to your submit that you made some days ago? Any positive?
Hello there! I know this is kind of off topic but I was wondering if you knew where I could get a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having trouble finding one? Thanks a lot!
I do love the manner in which you have presented this concern and it does indeed supply us some fodder for thought. However, because of everything that I have observed, I just simply trust when the actual opinions pile on that individuals remain on point and not embark upon a tirade regarding some other news of the day. All the same, thank you for this superb point and whilst I do not really go along with the idea in totality, I respect your perspective.