RE: Opening the dialog on button click
Hi Sam,
To open up the dialog box on button click, you can use functions given below.
Just copy and Paste the Javascript Functions in the Javascript Library file like this -
Open Form Editor:
1. Go To “Form Properties” Option.
2. A New Form Open, Click Events Tab.
3. Click on “Add” button from Event Handler Section. Specify the function name to call on selected event. Click Save.
4. Now, click “Edit Library” button from Event Handler Section. Copy and Paste functions given below in the form.
function runDialog() {
var dialogID = "F0BC9064-7F1B-4046-AD68-A4CDCSJGDJSJKA";
var today = new Date();
var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');
var time = 2000;
var objId = Xrm.Page.data.entity.getId();
setTimeout(
function () {
window.showModalDialog(serverUri + '?DialogID={' + dialogID + '}&EntityName=lead&ObjectId=' + objId, null, 'width=615,height=480,resizable=1,status=1,scrollbars=1');
}, time);
}
// To Open Quick Create Form
function OpenFeedbackForm() {
//lookup object of current lead record
var parrentLead = {
entityType: "lead",
id: Xrm.Page.data.entity.getId()
};
var parameters = {
companyname: Xrm.Page.getAttribute("companyname") != null && Xrm.Page.getAttribute("companyname").getValue() != null ? Xrm.Page.getAttribute("companyname").getValue() : "",
fullname: Xrm.Page.getAttribute("fullname") != null && Xrm.Page.getAttribute("fullname").getValue() != null ? Xrm.Page.getAttribute("fullname").getValue() : "",
jobtitle: Xrm.Page.getAttribute("jobtitle") != null && Xrm.Page.getAttribute("jobtitle").getValue() != null ? Xrm.Page.getAttribute("jobtitle").getValue() : "",
new_agenda: Xrm.Page.getAttribute("new_agenda") != null && Xrm.Page.getAttribute("new_agenda").getValue() != null ? Xrm.Page.getAttribute("new_agenda").getValue() : "",
ownerid: Xrm.Page.getAttribute("ownerid") != null && Xrm.Page.getAttribute("ownerid").getValue() != null ? Xrm.Page.getAttribute("ownerid").getValue() : "",
new_smename: Xrm.Page.getAttribute("new_smename") != null && Xrm.Page.getAttribute("new_smename").getValue() != null ? Xrm.Page.getAttribute("new_smename").getValue() : "",
decisionmaker: Xrm.Page.getAttribute("decisionmaker") != null && Xrm.Page.getAttribute("decisionmaker").getValue() != null ? Xrm.Page.getAttribute("decisionmaker").getValue() : "",
purchasetimeframe: Xrm.Page.getAttribute("purchasetimeframe") != null && Xrm.Page.getAttribute("purchasetimeframe").getValue() != null ? Xrm.Page.getAttribute("purchasetimeframe").getValue() : ""
};
Xrm.Utility.openQuickCreate("Lead", parrentLead, parameters).then(function (lookup) { successCallback(lookup); }, function (error) { errorCallback(error); });
}
function successCallback(lookup) {
alert('succes');
console.log("lookup: " + lookup.savedEntityReference.id);
}
function errorCallback(e) {
console.log("Error: " + e.errorCode + " " + e.message);
}
5. Click Save and Publish.
Please mark my answer as verified, if it solve your query.