I create 2 webresource and I want when the item of field (option set type) was chosen one of webresource hide.
Field name: ClientType
Webresource1: GreenColor
Webresource2: RedColor
I don't know the javascript code to fix this problem.
*This post is locked for comments
It was fixed andc everything ok. Thanks
I can repeat - everything depends on the logic you want to implement. I believe that if value is null all the webresources should be hidden and code I provided in previous reply works fine. If you need something else - I don't have telepathic skills to read your mind.
what about the null condition? what is the code?
If you have null it's up to you to decide what logic to apply. As for me you don't need that huge if..else sequence. Check how your code can look like without it:
function SetFieldInvisibleByVlaue(){ var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue(); Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(ClientType == "1"); Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(ClientType == "3"); Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(ClientType == "2"); }
That is the fourth condition so you will have a structure of this sort :
function SetFieldInvisibleByVlaue(){
var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();
if (ClientType == 1){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(true);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);
}
else if (ClientType== 2){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false); Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(true);
}
else if (ClientType== 3){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false); Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(true);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);
}
else{
//Null logic goes here
}
}
With just else you don't give condition. It will go there if all your above conditions doesn't meet.
Another good practice is to check for null in the first step itself.
Please be attentive while checking your condition
Cheers,
Gaurav
function SetFieldInvisibleByVlaue(){
var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();
if (ClientType == "1"){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(true);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);
}
else if (ClientType== "2"){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(true);
}
else ClientType== "3"){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(true);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);
}
}
Do you mean:
function SetFieldInvisibleByVlaue(){
var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();
if (ClientType == "1"){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(true);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);
}
else if (ClientType== "2"){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(true);
}
else ClientType== "3"){
Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(true);
Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);
}
}
And when I had a null condition what can I do?
Hi Amin,
It goes kike this:
if(condition1){
}
else if(condition2){
}
else{
}
Cheers,
Gaurav
If we had 3 condition what should to do? If ---- else If ----- else if ???
I checked ...... Completely worked
Thanks
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156