i want to enable mandatory for particular field (periodfrom and periodto )when i click on AMC check box ?
*This post is locked for comments
Dear all ,
Thanks
finally I got solution please find below javascript code
function addOrderType(item) {
debugger;
if (item.value == "AMC" && item.checked == true) {
parent.window.Xrm.Page.getAttribute("new_amcperiodfrom").setRequiredLevel("required");
parent.window.Xrm.Page.getAttribute("new_amcperiodto").setRequiredLevel("required");
document.getElementById("so_ordertype_3").disabled = true;
document.getElementById("so_ordertype_4").disabled = true;
document.getElementById("so_ordertype_5").disabled = true;
document.getElementById("so_ordertype_6").disabled = true;
}
if (item.value == "AMC" && item.checked == false) {
parent.window.Xrm.Page.getAttribute("new_amcperiodfrom").setRequiredLevel("none");
parent.window.Xrm.Page.getAttribute("new_amcperiodto").setRequiredLevel("none");
document.getElementById("so_ordertype_3").disabled = false;
document.getElementById("so_ordertype_4").disabled = false;
document.getElementById("so_ordertype_5").disabled = false;
document.getElementById("so_ordertype_6").disabled = false;
}
}
Hi Sabih,
Modified Aric's code , accessing from web resource to form using window.parent.
Just replace the field name and trigger in on change of checkbox which you want.
function chkAMC_OnChange() { var isChecked = Xrm.Page.getAttribute("new_chkAMC").getValue(); if (isChecked) { window.parent.Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("required"); window.parent.Xrm.Page.getAttribute("new_toDate").setRequiredLevel("required"); } else { window.parent.Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("none"); window.parent.Xrm.Page.getAttribute("new_toDate").setRequiredLevel("none"); } }
Take the help of the following code. Hope it helps:
$(document).ready(function() {
$("#chekcboxControlId").change(function() {
if(this.checked) {
window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("required");
}
else
{
window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("none");
}
});
});
If my answer helped to resolve your issue, kindly verify it by clicking 'Yes'. It would be helpful to the other community members seeking to resolve a similar issue.
Cheers
Arpit
https://arpitmscrmhunt.blogspot.in
Hi,
then refer to the link, on that particular checkbox checked, trigger the JS
function myFunction()
{
if(htmlcheckbox== true)
window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("required");
else
window.parent.Xrm.Page.getAttribute("fieldschema").setRequiredLevel("none");
}
Hi Wei Jie Fun,
yes all the checkbox are built using html
Hi,
for all the checkboxes, are they built using html code?
if yes, follow below post
checkbox of AMC using from option set so how to write javascript code
You can do this using JavaScript or Business Rule.
On the change event of the checkbox, set the Requirement Level of the two fields to required.
Using JavaScript:
function chkAMC_OnChange()
{
var isChecked = Xrm.Page.getAttribute("new_chkAMC").getValue();
if (isChecked)
{
Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("required");
Xrm.Page.getAttribute("new_toDate").setRequiredLevel("required");
}
else
{
Xrm.Page.getAttribute("new_fromDate").setRequiredLevel("none");
Xrm.Page.getAttribute("new_toDate").setRequiredLevel("none");
}
}
JavaScript file should be created and uploaded to server as web resource.
Add Web Resource to form, and add the onChange event to the checkbox control and enter the function name where required.
Logic should be similar to above using Business Rules.
Hope this helps.
Hi,
you can use business rule to achieve this
community.dynamics.com/.../using-business-rules-to-hide-fields-and-make-them-required-as-needed
Hi Sabih,
You can use Business Rule or JavaScript to make field mandatory no other field change.
Thanks,
Shahbaaz
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