Announcements
Greetings !
I am working on a D365 Marketing Landing Page form that would be hosted in an external website.
Is it possible to conditionally set some fields to Business Required based on a condition in a Landing page that will be hosted externally?
Example - If my Business Type Option set (from the landing page) is selected as Type A then make fields F1, F2, F3 as Business Required and If it is Type B then make F5, F6 as Business Required.
I could have done this easily using Business Rules if it had been a normal CRM form.
Any tips on this would be really helpful.
Thanks,
Shyam
Hi Shyam,
Is your option set also a field on marketing form?(F0 or F7) and is it an option set field or actually a two options(boolean) field?
Furthermore, I want to confirm the effect you would like to set as "Business Required":
do you want to append a red asterisk after field? or just show/hide field?(Showing a field means the field is business required, hiding a field means the field is optional.)
The marketing form handler will only execute once, however, as ticket said, we could bind browser built-in JavaScript function(onChange event handler) to detect change of option set field.
Once everything get confirmed, then I could share you a demo.
Regards,
Clofly
Hi Clofly,
Trust you are doing good!
We are fine if the logic works at client level on the external page, In the workaround you mentioned, would the logic function only once after the form is loaded or would it function as many times as the condition meets?
In my Example - If my Business Type Option set (from the landing page) is selected as Type A then make fields F1, F2, F3 as Business Required and If it is Type B then make F5, F6 as Business Required.
Step 1: After form loads, I select Business Type as A ---- and Fields F1, F2, F3 would turn business required.
Step 2: I change the Business Type from A to B, would the Fields F1, F2, F3 become set as optional and Fields F5, F6 be set as Business Required?
Step 3: I change the Business Type from B to A again, would the Fields F5, F6 become set as optional and Fields F1, F2, F3 be set to Business Required ?
or only Step 1 work?
The reason why I am asking this is, we have requirements to conditionally hide/show as well as set the field as Business Required or Optional in our externally hosted landing page.
and we tried to hide a field based on one option set value using After Form Load function and were not able to achieve the results (the fields weren't hidden when I select the value for the first time).
One important thing that I might have not communicated properly in my previous post is
We raised a MS premier ticket to get some help and we got this as the response.
We have checked with our PG team on this ask as well as internal resources. As of now this would not be possible through a marketing form handlers. We currently have only functions that can work on formLoad, afterFormLoad, formSubmit or so. Since these are all a one-time function handlers it either happens at the start or at the end. In our ask, we will need a handler that monitors the whole page real-time for the change of the field value. As of now this is not possible through a marketing form handler. However you can go ahead and add your own JavaScript directly to the page as a web page development without a marketing form handler used in the code. We are working internally on this to check if this will come up as a feature in the future, however as of now we do not have a mechanism to execute this through JavaScript of a marketing page handler and you would have to code it in your page directly.
Regards,
Shyam
Hi Clofly,
I am working on a D365 Marketing Landing Page form that would be hosted in an external website.
We have to do some conditional hide and show based on field drop down value.
I tried to append the below code in marketing form HTML script.
<script>
console.log("SHOW ME");
debugger;
MsCrmMkt.MsCrmFormLoader.on("afterFormLoad", function(event) {
console.log("afterFormLoad");
var fieldvalue = document.getElementById('68c423a8-1cb6-ea11-a813-000d3a8b328e').value;
if (fieldvalue == "0")
{
document.getElementById('06d025e5-8da5-ea11-a812-000d3a8b33f5').style.visibility = 'hidden';
}
else if(fieldvalue == "1")
{
document.getElementById('06d025e5-8da5-ea11-a812-000d3a8b33f5').style.visibility = 'visible';
}
})
</script>
But when the Marketing Page is loaded the script doesn't seems to work as I can't get even the basic console.log() to run.
Any help on this would be really helpful.
Thanks,
Garima
Thanks Clofly, we will be working on this tomorrow and let you know the outcome.
Thanks,
Shyam
Hi Shyam,
Currently there is no Business Rules-liked option for us to control a marketing form.
A workaround is that you could create custom javascript function to achieve it.
Just run our custom function after form has been rendered.
However, the workaround has such limitations:
1. It will only set field as required at client side.
(For normal users, they will still need to fill required field, but for developer users, they might open inspector and remove the "required" property to ignore validation.)
2. We can only get specific field element by index number, because form loader won't generate corresponding id or class or attribute to fields.
e.g: Select First Name Field
Pure JavaScript:
document.getElementsByTagName("input")[0;
jQuery:
$('input').eq(0);
3. After field is added with "required" property, we need to create red asterisk label manually.
jQuery:
$('input').eq(0).prop('required', 'true');
$('*').insertBefore($('input').eq(0));
remove the "required" property of field after selected option not meets condition.
$('input').eq(0).removeAttr('required'); // remove asterisk $('input').eq(0).prev().remove();
Regards,
Clofly
André Arnaud de Cal...
294,095
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator