HI Everyone !
I need some suggestion and code for auto populate lookup field from other entity ,
ex: if i select parent account lead /existing account all the related field should populate in lead please give some code .
thank you in advance !
HI Everyone !
I need some suggestion and code for auto populate lookup field from other entity ,
ex: if i select parent account lead /existing account all the related field should populate in lead please give some code .
thank you in advance !
Thank you so much Bipin
see this ,
// JavaScript source codefunction setLookup(executionContext) {
var formContext = executionContext.getFormContext();
var account = formContext.getAttribute('parentaccountid').getValue()[0].id.slice(1, -1);//get account id
if (account != null) {
Xrm.WebApi.online.retrieveRecord("account", account, "?$select=_st_country_value,_st_state_value").then(
function success(result) {
var _new_country_value = result["_st_country_value"];
var _new_country_value_formatted = result["_st_country_value@OData.Community.Display.V1.FormattedValue"];
var _new_country_value_lookuplogicalname = result["_st_country_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
var _new_state_value = result["_st_state_value"];
var _new_state_value_formatted = result["_st_state_value@OData.Community.Display.V1.FormattedValue"];
var _new_state_value_lookuplogicalname = result["_st_state_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (_new_country_value != null || _new_state_value != null) {
var Country = new Array();
var State = new Array1();
Country[0] = new Object();
State[0] = new Object1();
Country[0].id = _new_country_value;
State[0].id = _new_state_value
Country[0].name = _new_country_value_formatted;
State[0].name = _new_state_value_formatted;
Country[0].entityType = _new_country_value_lookuplogicalname;
State[0].entityType = _new_state_value_lookuplogicalname;
formContext.getAttribute("st_country").setValue(Country);
formContext.getAttribute("st_state").setValue(state); //set the counrty lookup field value in lead
}
else
{
alert("No Contact");
}
},
function (error)
{
Xrm.Utility.alertDialog(error.message);
}
);
}
Yes, same code can be used for other lookup.
HI Bipin,
Actually 2fields values i need to populate for ex: state and country from one entity to other entity like A and B lookup from X entity to Y entity .
Hi,
What do you mean by 2 lookup value?
Are you referring to multi entity lookup?
Hi Bipin ,
Can this will be used when 2 lookup values i need to update also .
Thank you so much it is working .
Hi,
I fixed this error.
Please try my code.
CRM.webapi.retrieverecord second parameter you are passing contact which does not exist, instead you should pass account.
This was your code mistake so I updated and replied with correct code.
HI Bipin,
I'm getting below error,
Hi,
I updated your code. Please try and confirm if you get any error -
function setLookup(executionContext) {
var formContext = executionContext.getFormContext();
var account = formContext.getAttribute('parentaccountid').getValue()[0].id.slice(1, -1);//get account id
if (account != null) {
Xrm.WebApi.online.retrieveRecord("account", account, "?$select=_new_country_value").then(
function success(result) {
var _new_country_value = result["_new_country_value"];
var _new_country_value_formatted = result["_new_country_value@OData.Community.Display.V1.FormattedValue"];
var _new_country_value_lookuplogicalname = result["_new_country_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (_new_country_value != null) {
var value = new Array();
value[0] = new Object();
value[0].id = _new_country_value;
value[0].name = _new_country_value_formatted;
value[0].entityType = _new_country_value_lookuplogicalname;
formContext.getAttribute("new_country").setValue(value); //set the counrty lookup field value in lead
}
else {
alert("No Contact");
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156