Came across a requirement on Dynamics Community to restrict Phone Call Quick Create form when clicked on a Phone Number to open Call App (Skype or Custom). The reason being, phone call is automatically created by 3rd-party telephony solution.
There is no out-of-the-box configuration available to prevent this. As shown in below snapshot, Default behavior launches both the configured telephony app (based on TEL protocol) and Phone Quick Create form:
As mentioned, no way to block this, but, where there’s a will, there’s a way!
Let’s hack it!
Problem
Prevent Phone Quick Create form when user clicks on Phone Call button (Click-to-call)
Solution
We cannot stop the Phone Quick Create form from opening, however we can close it forcefully. But, we need to identify, if the form is launched by clicking on click-to-call button. Luckily, when Phone Quick Create form is opened form Click-to-Call, it passes a query string parameter named contactinfo, and the value starts with ‘tel:‘. For instance, if you click on a phone field which has +100100100100 as number, it will pass following value to the Phone Quick Create form:
tel:+100100100100
Now all we have to do is, close the form when contactinfo starts with ‘tel:’. This means form will be closed when launched from Click-to-Call, but it will work in all other scenarios, like when user creates a Phone Call form timeline.
Here are the steps to follow:
- Open the Default Solution (or your custom solution).
- Create a Script Webresource (or use existing), and add the following function:
function phOnLoad(executionConext) {
var formContext = executionConext.getFormContext();
var formType = formContext.ui.getFormType();
if (formType != 1) { // If not Create, optional check as form is Quick Create
return;
}
var params = Xrm.Utility.getGlobalContext().getQueryStringParameters();
var contactinfo = params.contactinfo;
if (contactinfo != null && contactinfo != undefined
&& contactinfo.startsWith("tel:")) {
// If Form is opened from TEL protocol, close the form forcefully.
formContext.ui.close();
}
}
- Expand Entities -> Phone Call -> Forms.
- Open the Phone Quick Create form and click on form properties in the ribbon.
- Register this function onLoad of the form, do not forget to pass the execution context.
- Save and Publish.
Result
Now when user presses the Click-to-Call button on a Phone field, Quick Create is automatically closed:
I understand it is not an elegant solution, as the form shows for split of second and then closes automatically, however this is the best we can do at the moment.
That’s it, quite easily done!
*This post is locked for comments