Hi
I'm a total novice when it comes to Javascript so I was just wondering if anyone could help with this code?
I want to hide a tab if the user is viewing a form on desktop and show it if they are using mobile.
Here's what I have so far:
// If mobile, show mobile tab, otherwise don't.
var showMobileTab;
function OnLoad (executionContext) {
var form = executionContext.getFormContext();
var context = executionContext.getContext();
var isCrmForMobile = (Xrm.Page.context.client.getClient() == "Mobile")
if (isCrmForMobile)
}
// RateCard.showMobileTab = showMobileTab
function showMobileTab(executionContext) {
form.ui.tabs.get("mobile")
.setVisible(true);
}
else
{
// RateCard.showMobileTab = showMobileTab
function showMobileTab(executionContext) {
form.ui.tabs.get("mobile")
.setVisible(false);
}
Thanks in advance.
Hi rtrickey,
It's glad to see that your issue has been solved perfectly,
and thanks for sharing solution.
Have a good day. :)
Regards,
Clofly
Hi Clo
I've changed the code to display sections rather than tabs and it works perfectly.
Here's the final code:
// If mobile, show mobile section, otherwise show desktop section.
function onLoad(executionContext) {
var onLoad;
var form = executionContext.getFormContext();
var context = executionContext.getContext();
var isCrmForMobile = (Xrm.Page.context.client.getClient() == "Mobile")
if (isCrmForMobile) {
form.ui.tabs.get("summary").sections.get("mobile").setVisible(true);
} else {
form.ui.tabs.get("summary").sections.get("desktop").setVisible(true);
}
}
Thanks for all your help.
Hi retro key,
I didn’t encounter this issue in iOS application.
You could remove setVisible(true) function.(not do any action if the client is mobile)
Regards,
colfly
Hi Clo
What I meant is the re-ordering isn't an issue as I only have one tab.
The issue is that the data does not automatically appear - you have to physically click the tab for the fields to show. Have you experienced this before?
Thank you,
Hi rtrickey,
What does "it had no effect" mean ? It seems that Mobile has been added as first tab from your screenshot,
does Javascript code not work for display tab after re-ordering ?
Supplement:
Hi rtrickey, do you mean you should click screen then data in Mobile tab will display ?
You could try remove setVisible(true) .
Rrgards,
Clofly
Hi Clo, not quite.
I tried re-ordering as per above but it had no effect.
I've attached some screenshots of what I see for your reference.
Regards,
Ryan
Hi rtrickey,
Firstly I would like to point out that our user agent will only be recognized as 'Mobile' in Mobile Application.(AppStore or Google Play),
even if we works in mobile browser, CRM will still regard user agent as "Web".
From your description and as per my understand, do you mean you have to click the horizonal ellipsis to get the tab you want ?
For example, details tab is only available in Mobile application and it will be shown after clicking ellipsis icon:
Web:
Mobile:
If so, we should know that setVisible function is to control whether the specific tab be shown on form,
and your purpose might be you would like to show it as first tab(as Summary tab in screenshot).
Those tabs display order are decided by their top and bottom order in form editor,
so you should open form editor, and drag the tab you want to top, then it will show directly without have to open ellipsis drop-down menu:
(I dragged Details tab to top to replace Summary tab)
Now Details has been the first tab in mobile.
While Summary still be the first because Details tab was hidden.
Regards,
Clofly
Hi Clofly, thank you so much for your response. I've added the code and it works except the tab does not automatically appear on mobile, you have to click on it to show the figures. Anything I can do to make this display without clicking?
Thanks again.
Hi Partner,
You should fire the outter onLoad function in form settings instead of showMobileTab.
(Or you could change its name to showMobileTab as you would like)
A modified code could be below:
While you should also check Pass executioncontext .. option for your function.
And for get("mobile"), the parameter should be match with Tab Name property:
Regards,
Clofly