javascript - Unable to set the lookup with values on Entity form with lookup data from caller form in MS Dynamics CRM 2011 -
form : entity a
- field display name : approver
- field name : bch_signingauthority
- field type : lookup field
- source : user entity
- summarize : when approver lookup in entity: selected display list of records entity: users. entity
- name : bch_signingauthority
form : entity b
- field display name : approver
- field name : bch_approver
- field type : lookup
- field source : entity: , field name : approver
- summarize : when approver lookup selected display saved records of approver entity: a
functions: when select approver in entity:a , select html button have used code below send query string form entity : b
<html xmlns="http://www.w3.org/1999/xhtml"><head> <script type=text/javascript> function setdelegate(){ var approverinfo = new array(); approverinfo = window.parent.xrm.page.getattribute('bch_approver').getvalue(); if(approverinfo[0] != null) { var parameters = {}; parameters["formid"] = "{b053a39a-041a-4356-acef-ddf00182762b}"; window.parent.xrm.utility.openentityform("bch_delegate", approverinfoid ); } } </script> <meta charset=utf-8></head> <body><input onclick=setdelegate(); value="set delegate" type=submit> </body></html>
in form entity:b on page load have written following javascript code read , set lookup in entity: b
i have received query string using code below:
// value of regarding through customer parameters var param=xrm.page.context.getquerystringparameters(); if (param != null ) { alert('inside'); var approverid=param["bch_signingauthority"]; var bchname = param["bch_name"]; //populate regarding if there 1 //if (regardingid != undefined) //{xrm.page.getattribute("regardingobjectid").setvalue([{id:regardingid, name:regardingname, entitytype:regardingtype}]);} var = getapprovername(approverid); var lookup = new array(); lookup[0] = new object(); lookup[0].id = bchname; lookup[0].name = a; //alert(a.trim()); //alert(approverid); //lookup[0].entitytype = 'signing authority'; //xrm.page.getattribute('bch_signingauthority').setvalue(lookup); xrm.page.getattribute("bch_signingauthority").setvalue([{ id: bchname, name: a, entitytype: 'signing authority'}]); lookup[0] = new object(); lookup[0].id = approverid; lookup[0].name = a; xrm.page.getattribute('bch_approver_test1').setvalue(lookup); } } function getapprovername(approverid) { var result = ""; var serverurl = document.location.href.substring(0, document.location.href.indexof("/", 10)); var organizationname = xrm.page.context.getorguniquename(); serverurl = serverurl + "/" + organizationname; var fetchutil = new fetchutil(organizationname, serverurl); var _fetchxmlgetusername = "" + " <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> " + " <entity name='systemuser'> " + " <attribute name='fullname'/> " + " <attribute name='systemuserid'/> " //+ " <attribute name='createdon' /> " //+ " <attribute name='bch_approver' /> " + " <order attribute='fullname' descending='false' /> " + " <filter type='and'> " + " <condition attribute='systemuserid' operator='eq' uitype='systemuser' value='" + approverid + " ' />" + " </filter> " + " </entity> " + " </fetch> "; alert(_fetchxmlgetusername ); try { // find system user var systemuser = fetchutil.fetch(_fetchxmlgetusername); if (systemuser && systemuser.length > 0) { // var signingauthority = systemuser[0].attributes["bch_signingauthorityid"]; // alert(signingauthority.value); // var name = systemuser[0].attributes["bch_name"]; // alert(name.value); var systemusername = systemuser[0].attributes["fullname"]; // alert(systemusername.value); if ((systemusername != null) && (systemusername.value != null)) { result = systemusername.value; } } } catch (e) { alert('an error occured in getusername'); } return result; }
i not able set approver lookup/name: bch_signingauthority id being passed in via query string. can please , suggest me how go doing new crm dynamics 2011.
you have few issues .setvalue()
calls lookup attributes.
i recommend using this helper function form crm sdk:
function setsimplelookupvalue(lookupid, type, id, name) { var lookupreference = []; lookupreference[0] = {}; lookupreference[0].id = id; lookupreference[0].entitytype = type; lookupreference[0].name = name; xrm.page.getattribute(lookupid).setvalue(lookupreference); }
with function convert:
xrm.page.getattribute("bch_signingauthority").setvalue([{ id: bchname, name: a, entitytype: 'signing authority'}]);
to
setsimplelookupvalue('bch_signingauthority', 'signing authority', bchname, a);
the next issue code using "signing authority"
entitytype
. not valid entitytype
, should logical name of entity lookup references. in this, believe bch_signingauthority
lookup systemuser
should 'systemuser'
, , therefore read follows:
setsimplelookupvalue('bch_signingauthority', 'systemuser', bchname, a);
Comments
Post a Comment