Introduction:
In our previous blogs of the ‘Controls in Dynamics 365 for Mobile App’ series, we discussed Input Mask, Multimedia, Website Preview, Auto-Complete, Option set, Star Rating controls and Contract Calendar. The Contract Calendar Control may help you to view the time table in order to understand what time the task needs to be performed on weekly basis. Contract calendar Control can be used as Task Scheduler on weekly basis on Mobile and Tablet.
Today in this blog let’s discuss about another control in Dynamics 365 called ‘Flip Switch’.
What is Flip switch and how it can help users?
The Field Type to use Flip Switch would be ‘Two options’.
If you go by UI perspective, Flip switch control- Yes/No (Boolean) options would give the nice field look in the web, mobile app and Tablet. Instead of using check boxes and radio buttons, this control adds a visual effect like the On/Off switch way.
Let us see an example where we have added Flip Switch control on the Account entity record:
In this example, we will add the Flip Switch control on the Account entity record. We need to use the visual effect of Flip Switch to see whether the Account is Taxable or not.
1. First, create a new field ‘Taxable’ with ‘Data type’ as ‘Two Options’ as seen in the screenshot below:
Here, we have kept the default value of “Taxable” field as “No”.
2. Now, add this field on Account Form and click on the ‘Field ‘ Select the ‘Controls’ tab and click on ‘Add Control.’ Then choose the Flip-Switch control as shown in the screenshot below:
Note: When you add the control, the “Visible by default” for the field sets to “No”. So once done adding the controls, need to again set the “Visible by default” value as “Yes”.
3. Click on ‘Save’ and ‘Publish’ the customizations. Once you save the record, log in to Dynamics 365 Mobile and Tablet app and open the Account entity record in which you have put the Taxable field. You will now see Yes/No represented as Flip switch as seen in the screenshot below:
4. This control also works on web client. To view Flip switch control on web client, navigate to Account entity and see the look of the “Taxable” field.
Conclusion:
The Flip Switch control is helpful in situations where a user needs to show the simple Yes/No two options in an effective way. It adds an interactive visual element for users in Dynamics 365 web, Mobile and Tablet app!
Nice Article!
May I know how to set value in this control using JavaScript?
Thanks
Yes we can set the field using JS by using the below code:
formContext.getAttribute(“donotemail”).setValue(true);
Please find the sample scenario below:
function flipSwitchExample(executionContext) {
var functionName = “flipSwitchExample “;
try {
var formContext = executionContext.getFormContext();
var creditonhold = formContext.getAttribute(“creditonhold”).getValue();// on change of the field set the “donotemail”
//validate creditonhold = Yes(true)
if (creditonhold) {
//set donotemail(i.e. Flipswitch)
formContext.getAttribute(“donotemail”).setValue(true);
}
} catch (error) {
Xrm.Utility.alertDialog(functionName + “: Error: ” + (error.message || error.description));
}
}
Thanks!
Hi.
I have added this control for my Two option attibutes. I am not able to fire the javascript code on change of this control.
Does it not support onchange event?
Is there any change required to fire my onchange event upon setting fip-switch control?
Hi,
Yes, It supports on change event. You do not have to do any change to fire on change event after setting flip-switch control.
I have tried the same and its working for me.
Could you please confirm how you are triggering this on change event? Means are you updating this field manually or through custom JavaScript code? If you are updating through custom java script code then you need to add “fireOnChange()” event on that attribute.
Please refer this link : https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/attributes/fireonchange
Thanks!
How to enable this control on Business Process Flow?
I have added this Two Option field in BPF and want to update it as Flip-Switch Control
I am not finding a way to do this
Thank you in advance
The Flip switch is a PCF control. You could follow the steps illustrated in this blog to include custom controls in BPF https://powerusers.microsoft.com/t5/Power-Automate-Community-Blog/Preview-Custom-Controls-in-Business-Process-Flows/ba-p/263237