Requirement
– Placed a button inside the form. On click of that button will open a child popup window and set the filter criteria. Upon closing the popup window, the criteria will be stored in parent window.
Step 1: Create a field (Name: textField1)
with data type Single line of text box.
Step 2: Drag this field to form on
which section required to display button.
Step 3: In the field properties, Unchecked
the label text box. So only the text box will be appeared on form.
Step 4: On form add one more text field
( Name : textField2) which you want to
capture the data set on popup window.
Step 5: Form load event call ButtonCreate
method.
Function ButtonCreate(textField1) {
var buttonfield =
document.getElementById(textField1);
if (buttonfield == null)
buttonfield =
parent.document.getElementById(textField1);
if (buttonfield != null) {
var parentDiv = buttonfield.parentNode;
var parentTd = parentDiv.parentNode;
var parentTr = parentTd.parentNode;
parentDiv.removeChild(buttonfield);
var div = document.createElement("div");
div.style.width = "19%";
div.style.textAlign = "right";
div.style.display = "inline";
div.innerHTML = '<button
id="textField2" type="button" class="ms-crm- Button"
>Edit</button>';
parentDiv.appendChild(div);
parentTd.style.display = 'block';
parentTd.visible = 'true';
parentTr.style.display = 'block';
parentDiv.style.display = 'block';
var newField = document.getElementById(textField2);
if (newField == null)
newField =
parent.document.getElementById(textField2);
newField.onclick
= function () {onnewbuttonclick(); };
}
};
function onnewbuttonclick() {
var fetchxml = Xrm.Page.getAttribute("new_textfield2").getValue();
var typecode
= Xrm.Page.getAttribute("new_entitytypecode").getValue();
if (!typecode || typecode == '') {
return;
}
var
dialogurl = '/Tools/ViewEditor/Dialogs/SetFilters.aspx?entityCode=' + typecode;
var dialogOptions = new Xrm.DialogOptions();
dialogOptions.width = 600;
dialogOptions.height = 600;
var argments = {};
if (fetchxml && fetchxml != '') {
argments.sFetchXml = fetchxml;
}
var sFeatures = "dialogHeight: " + 600 + "px; dialogWidth: " + 600 + "px;";
Xrm.Internal.openDialog(Mscrm.CrmUri.create(dialogurl).toString(),
dialogOptions,
argments, null,
function (result) {
if (result) Xrm.Page.getAttribute("new_textfield2").setValue(result.sFetchXml);
});
};
