c# - How to add a value to a lookup field? -


i have entitiy "account "in has name_field in microsoft dynamics crm. other lookup field , every other fields values can inserted. how select existing value in up????

i used following code add value lookup field.. don't error..

account acc = new account(); acc.attributes["name"] = "ram"; // values got inserted acc.attributes["age"] = "22"; // values got inserted acc.attributes["lookupfieldid"] = "sampletext";  service.create(acc); // create account 

how need change code in order select "primary" value in lookup field?

lookup fields in crm 2011 entityreference, means need know logicalname of entity lookup pointing , id of record.

so code wil be:

account acc = new account(); acc.attributes["name"] = "ram"; // values got inserted acc.attributes["age"] = "22"; // values got inserted  acc.attributes["lookupfieldid"] = new entityreference("contact", contactid); // if lookupfieldid pointing contact entity  service.create(acc); // create account 

one consideration: wrote

account acc = new account(); 

i don't know if using bound (means classes generated crmsvcutil.exe) or late bound (in case write entity acc = new entity("account");)

but if use bound, syntax like:

account acc = new account(); acc.name = "ram"; // values got inserted acc.age = "22"; // values got inserted acc.lookupfieldid = new entityreference("contact", contactid); // if lookupfieldid pointing contact entity service.create(acc); // create account 

using bound know before right type expected field.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -