Microsoft Dynamics Portal provides capability to allow login customers without needed any license. Here I am not explaining benefits of Dynamics Portal. I am going to show a use case for developers.
Case Study: - There is a requirement in portal where we need to make attach note section mandatory based on value of quick view form. Now Quick view form is supported by Dynamics Portal. So, it is nice to use Quick view form to show information based on lookup value.
While creating a case from portal, customer needs to select reason (lookup field). On selection of this lookup Quick view form displayed with required document list and a Boolean field which specify document is required or not.
Based on this Boolean field value need to make attachment required or not.
Solution: - We need to use Javascript to complete this requirement.
- Login to Dynamics Portal with Administrator rights.
- Click on “My Support” button than “Open a New Case” button.
- Once create case page is opened click on edit button.
- Once edit section is opened, click on “Option” tab.
- Now add your Javascript code in “Custom JavaScript”text block.
- Click on Save button.
JavaScript Code
///////////////////////////////// Code Started ///////////////////////////////////////////
$(document).ready
(
function () {
$('iframe#MandatoryInformation').load(function () {
setTimeout(getdoc, 50);
});
}
);
function getdoc() {
let iframe = document.getElementById("MandatoryInformation");
var innerDoc = (iframe.contentDocument)
? iframe.contentDocument
: iframe.contentWindow.document;
// check document requirement
let isDocRequired = innerDoc.getElementById("boolean_field_schemaName_1");
if (isDocRequired) {
if (isDocRequired.checked) {
//make attachment mandatory
addNoteValidator("AttachFile", "AttachFileLabel");
}
else {
//make attachment non mandatory
removeNoteValidator("AttachFile", "AttachFileLabel");
}
}
else {
//make attachment non mandatory
removeNoteValidator("AttachFile", "AttachFileLabel");
}
}
function addNoteValidator(fieldName, fieldLabel) {
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
$("#" + fieldLabel).parent().addClass("required");
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "RequiredFieldValidator" + fieldName;
newValidator.controltovalidate = "casetypecode";
newValidator.errormessage = "<a href='#" + fieldLabel + "'>" + "Make sure you should attach all required documents.</a>";
newValidator.validationGroup = "";
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
var value = $("#" + fieldName).val();
if (value == null || value == "") {
return false;
} else {
return true;
}
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);
// Wire-up the click event handler of the validation summary link
$("a[href='#" + fieldLabel + "']").on("click", function () { scrollToAndFocus(fieldLabel + '', fieldName); });
}
function removeNoteValidator(fieldName, fieldLabel) {
$.each(Page_Validators, function (index, validator) {
if (validator.id == "RequiredFieldValidator" + fieldName) {
Page_Validators.splice(index, 1);
}
});
$("#" + fieldLabel + "").parent().removeClass("required");
}
///////////////////////////////// Code Ended///////////////////////////////////////////
Code Explanation: -
- On Load of create case page we are adding “On Load” event to our Iframe. This event will fire on change to content of your “Quick View Form”.
$('iframe#MandatoryInformation').load(function () {
// use setTimeout to complete Iframe load.
setTimeout(getdoc, 50);
});
- Timeout is used because Iframe takes some time to load completely.
- Select Iframe content
let iframe = document.getElementById("MandatoryInformation");
var innerDoc = (iframe.contentDocument)
? iframe.contentDocument
: iframe.contentWindow.document;
- check document requirement field value
let isDocRequired = innerDoc.getElementById("boolean_field_schemaName_1");
if (isDocRequired) {
if (isDocRequired.checked) {
- Make attachment mandatory if Boolean in true
addNoteValidator("AttachFile", "AttachFileLabel");
- Remove attachment mandatory if Boolean in false
removeNoteValidator("AttachFile", "AttachFileLabel");
Result: -
- If Field value is true.
- If Field value is false.
Share your feedback and follow blog to be updated !!














