Hello All Experts,
I need to open a quick create form of contact entity from one account form using custom button click.
but i need to also pass some value like account details like (id, name) which should get setup on the field present on the contact form.
Till now .
1. I have customized the button using ribbon workbench and called a function which can open the quick create form.
2. I am not sure how to set the value in the account lookup field present on the contact form.
I am utilizing below code to open quick create form.
function openquickCreateForm(){
// *** First get the Id of the required account, possibly like this ....
var accountValue = null;
var account = Xrm.Page.getAttribute("new_account");
if (account != null) {
accountValue = account.getValue();
if (accountValue != null) {
var accountId = accountValue[0].id;
}
}
// ** Create an object including the accountId. Used to call the
// ** quick create form in the context of the account
var parentAccount = {
entityType: "account",
id: accountId,
name: accountValue.name
};
// *** NOTE: Here we aren't setting any parameters! (But we could!)
var parameters = { };
// *** Call the Xrm.Utility needed to add a contact.
Xrm.Utility.openQuickCreate("contact", parentAccount, parameters).then(function (lookup) { successCallback(lookup); }, function (error) { errorCallback(error); });
// *** Function called on success.
function successCallback(lookup) {
alert("lookup: " + lookup.savedEntityReference.id);
alert("lookup: " + lookup.savedEntityReference.name);
}
// **** Function called on error.
function errorCallback(e) {
// *** No new contact created, which is an error we can ignore!
alert("Error: " + e.errorCode + " " + e.message);
}
}
and trying to bind the data into the account lookup using below function
function bindAccountlookup()
{
if (Xrm.Page.ui.getFormType() == 1) {
var lookupValue = new Array();
lookupValue[0] = new Object();
var queryParam = Xrm.Page.context.getQueryStringParameters();
if (queryParam.Data) {
arrayObject = JSON.parse(queryParam.Data);
lookupValue[0].id = arrayObject[0].id;
lookupValue[0].name = arrayObject[0].name;
lookupValue[0].entityType = "account"; //Entity Type of the lookup entity
Xrm.Page.getAttribute("new_account").setValue(lookupValue);
}
}
}
The above two highlighted lines do not have that lookup value which i need to set.
Any help will be appreciable.