Hi preetham,
To set lookup field(preetham_refferdid) value, we should create an array object with id, name and entityType properties.
Please modify your Xrm.WebApi.retrieveMultipleRecords function like below.
Xrm.WebApi.retrieveMultipleRecords("preetham_doctors", fetchxml).then( function success(response) { for (var i = 0; i < response.entities.length; i ) { var responseobj = response.entities[i]; var lookup = new Array(); lookup[0] = new Object(); lookup[0].id = responseobj.preetham_doctorsid; lookup[0].name = responseobj.preetham_name; lookup[0].entityType = 'preetham_doctors'; formcontext.getAttribute("preetham_refferedid").setValue(lookup); } }, function (error) { Xrm.Utility.alertDialog("failed"); } )
Alternatively, it also works if we shorten them in single line.(Not declaring array and object.)
formcontext.getAttribute("preetham_refferedid").setValue([{id: responseobj.preetham_doctorsid, name: responseobj.preetham_name, entityType:'preetham_doctors'}]);
Regards,
Clofly
Addfilter is not triggering is ther any otherway to do it .
i have tried using webapi
function Alertmethod(executionContext)
{
var formContext = executionContext.getFormContext(); // get formContext
debugger;
var department_id=formContext.getAttribute("preetham_departmentid").getValue()[0].id
var fetchxml="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
" <entity name='preetham_doctors'>"+
" <attribute name='preetham_doctorsid' />"+
" <attribute name='preetham_name' />"+
" <attribute name='createdon' />"+
" <order attribute='preetham_name' descending='false' />"+
" <filter type='and'>"+
" <condition attribute='preetham_departmentsid' operator='eq' value='"+department_id+"' />"+
" </filter>"+
" </entity>"+
"</fetch>"
fetchxml="?fetchXml="+encodeURIComponent(fetchxml);
Xrm.WebApi. retrieveMultipleRecords("preetham_doctors",fetchxml).then(
function success(response)
{
for(var i=0; i<=response.entities.length; i++)
{
var responseobj=response.entities[i];
formcontext.getAttribute("preetham_refferedid").setValue(responseobj.preetham_doctorsid)
}
},
function(error)
{
Xrm.Utility.alertDialog("failed");
}
)
}
I am getting the data in response but i am not able to set to "preetham_refferdid"
Any idea is i am doing correct or any suggestion
You can insert debugger at line 1 of addFilter function, to check whether the addFilter is actually triggered by addPreSearch.
Hi Clofy Mao
Thats not the problem
formContext.getControl("preetham_refferedid").addPreSearch(addFilter);
in this addPreSearch should call addfilter function but its not calling addfilter its terminating .
community.dynamics.com/.../845868
I found this i am also using version 9.0
Hi preetham,
Maybe it caused by this line
department=department[0].id
It will get the record id and curly bracket, please remove the extra bracket using regex and test again.
department[0].id.replace(/\{|\}/gi, "").toLowerCase();
Regards,
Clofly
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,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156