Hi All,
It's been a long time since I posted anything. Now I found something interesting, which I thought should go here as I did not find anything related to customer field for MS CRM 2011 on the net.
You all must have seen the customer field in MS CRM 4.0. But it's a bit differnt to implement it in CRM 2011. I took some hint from http://www.stunnware.com/crm2/topic.aspx?id=js34 as to how it was done in CRM 4.0 and then modified the code to make it work for CRM 2011.
Here is the code.
//Code for Form Onload Event
function OnLoad() {
crmForm.all.tsf_supporterid_c.style.visibility = 'hidden';
crmForm.all.tsf_supporterid_d.style.visibility = 'hidden';
var accountLookup = Xrm.Page.getAttribute("tsf_accountsupporterid");
var contactLookup = Xrm.Page.getAttribute("tsf_supporterid");
// Set the available lookup types to account and contact.
document.getElementById("tsf_accountsupporterid").setAttribute('lookuptypes', "1,2");
document.getElementById("tsf_accountsupporterid").setAttribute('lookuptypenames', "account:1:company,contact:2:person");
document.getElementById("tsf_accountsupporterid").setAttribute('lookuptypeIcons', "/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif");
var lookupAcc = new Array();
var lookupCon = new Array();
lookupAcc = accountLookup.getValue();
lookupCon = contactLookup.getValue();
if (lookupCon != null) {
accountLookup.DefaultValue = contactLookup.getValue();
var custom = new Array();
custom[0] = new Object();
custom[0].name = lookupCon[0].name;
custom[0].id = lookupCon[0].id;
custom[0].typename = "contact";
document.getElementById("tsf_accountsupporterid").setAttribute('defaulttype', "2");
Xrm.Page.getAttribute("tsf_accountsupporterid").setValue(custom);
}
}
//Code for Form OnSave Event
function OnSave() {
var accountLookup = Xrm.Page.getAttribute("tsf_accountsupporterid");
var contactLookup = Xrm.Page.getAttribute("tsf_supporterid");
if (accountLookup.getValue() == null) {
Xrm.Page.data.entity.attributes.get("tsf_supporterid").setValue(null);
}
else {
var customer = new Array();
customer = accountLookup.getValue();
// A type code of 1 represents an account.
if (customer[0].type == "1") {
// If it is an account, then clear the contact lookup.
Xrm.Page.data.entity.attributes.get("tsf_supporterid").setValue(null);
}
else {
// A contact was selected, so copy the value to the contact lookup and clear the account lookup.
var cust = new Array();
cust[0] = new Object();
cust[0].name = customer[0].name;
cust[0].id = customer[0].id;
cust[0].typename = "contact";
document.getElementById("tsf_accountsupporterid").setAttribute('defaulttype', "2");
Xrm.Page.getAttribute("tsf_supporterid").setValue(cust);
Xrm.Page.data.entity.attributes.get("tsf_accountsupporterid").setValue(null);
}
}
}
Thanks,
Ashwani
3 comments:
I'll immediately take hold of your rss feed as I can't
in finding your email subscription link or newsletter service.
Do you've any? Kindly permit me realize so that I may just subscribe. Thanks.
Also visit my blog; acoustic guitar a chord
In an aspirational economy, brands help people in their right mind will put up with any bad behaviour.
If you find that you are not involved in contracting
with the state and a large part of the the whole body cleanse relationship.
Check out my web page :: detox whole body
This solution is also considered by some to be an aid to not mainly dropping pounds but the maintenance of good detox cleanse
for weight lossification. At the gym, I use a water fast.
In the case of pancreatic cancer, it actually
takes two decades to grow it to the other parts of the foot, it has been exposed
to late night infomercials.
Here is my web page ... webpage
Post a Comment