Xrm.Utility : openEntityForm with Parameter
Using “openEntityForm” a CRM form can be opened. While it is opening, different form fields values can be populated and those values can be passed to the form.
Xrm.Utility.openEntityForm(name,id,parameters,windowOptions)
name: Entity Logical Name
id: Record id
parameters: Form id, Field Ids, and Values, Custom query string parameters
windowOptions: Flag to open as a New Window
name: Entity Logical Name
id: Record id
parameters: Form id, Field Ids, and Values, Custom query string parameters
windowOptions: Flag to open as a New Window
Passing Parameters and Populate Field Values in a New Contact Form
function openNewContact() {
var caseId = Xrm.Page.data.entity.getId();
var title = Xrm.Page.getAttribute(“title”).getValue();var windowOptions = {
openInNewWindow: true
};
var parameters = {};
parameters[“new_caseid”] = caseId;
parameters[“new_caseidname”] = title;
Xrm.Utility.openEntityForm(“contact”, null, parameters, windowOptions);
}
Passing Parameters and Populate Field Values in an Existing Contact Form
function openExistingContact() {
var caseId = Xrm.Page.data.entity.getId();
var title = Xrm.Page.getAttribute(“title”).getValue();var lookupObject = window.parent.Xrm.Page.getAttribute(“parentcontact”);if (lookupObject != null) {
var lookUpObjectValue = lookupObject.getValue();
if (lookUpObjectValue != null) {
var personId = lookUpObjectValue[0].id;var windowOptions = {
openInNewWindow: true
};var parameters = {};
parameters[“param_caseid”] = caseId;
parameters[“param_casetitle”] = title;
Xrm.Utility.openEntityForm(“contact”, personId, parameters, windowOptions);
}
}
}
Read parameters from the query string and set the fields on form load.
function contactFormOnLoad() {
var safestringParamCaseId;
var safestringParamCaseTitle;if (Xrm.Page.context.getQueryStringParameters().param_caseid != null && Xrm.Page.context.getQueryStringParameters().param_caseid != ‘undefined’) {
safestringParamCaseId = Xrm.Page.context.getQueryStringParameters().param_caseid;
}
if (Xrm.Page.context.getQueryStringParameters().param_casetitle != null && Xrm.Page.context.getQueryStringParameters().param_casetitle != ‘undefined’) {
safestringParamCaseTitle = Xrm.Page.context.getQueryStringParameters().param_casetitle;
}var lookupArray = new Array();
lookupArray[0] = new Object();
lookupArray[0].id = safestringParamCaseId;
lookupArray[0].name = safestringParamCaseTitle;
lookupArray[0].entityType = “incident”;
Xrm.Page.getAttribute(“new_tempcaseid”).setValue(lookupArray);
}
No comments:
Post a Comment