如何为查找字段添加值? [英] How to add a value to a lookup field?
问题描述
我有一个实体帐户,其中在Microsoft Dynamics CRM中有一个name_field。
除了lookup field之外,还可以插入其他所有字段的值。
我使用以下代码向查找字段添加值。.但是我没有得到任何错误..
Account acc = new Account();
acc.Attributes [ name] = Ram; //此值已插入
acc.Attributes [ age] = 22; //此值已插入
acc.Attributes [ lookupfieldid] = Sampletext;
service.Create(acc); //创建帐户
我如何更改代码以在中选择主要值查找字段?
CRM 2011中的查找字段为 EntityReference
,这意味着您需要知道查找指向的实体的 LogicalName
和记录的 Id
。
因此您的代码将是:
帐户acc =新帐户() ;
acc.Attributes [ name] = Ram; //此值已插入
acc.Attributes [ age] = 22; //此值已插入
acc.Attributes [ lookupfieldid] = new EntityReference( contact,contactId); //如果lookupfieldid指向联系人实体
service.Create(acc); //创建帐户
一个考虑:您写了
Account acc = new Account();
我不知道您是否使用早绑定(表示<$ c $生成的类c> crmsvcutil.exe )或后期绑定(在这种情况下,您将编写 Entity acc = new Entity( account);
)
,但是如果使用早绑定,则语法将类似于:
Account acc = new Account();
acc.Name = Ram; //此值已插入
acc.Age = 22; //此值已插入
acc.LookupFieldId = new EntityReference( contact,contactId); //如果lookupfieldid指向联系人实体
service.Create(acc); //使用早绑定来创建帐户
,您会在字段期望的正确类型之前知道。 / p>
I have a entitiy "account "in which it has some name_field in Microsoft Dynamics CRM. Other than lookup field , every other fields values can be inserted. how to select an existing value in look up????
I used the following code to add value to the lookup field.. However I don't get any error..
Account acc = new Account();
acc.Attributes["name"] = "Ram"; // this values got inserted
acc.Attributes["age"] = "22"; // this values got inserted
acc.Attributes["lookupfieldid"] = "Sampletext";
service.Create(acc); // to create account
How I need to change my code in order to select "primary" value in the lookup field?
Lookup fields in CRM 2011 are EntityReference
, this means you need to know the LogicalName
of the entity the lookup is pointing and the Id
of the record.
so your code wil be:
Account acc = new Account();
acc.Attributes["name"] = "Ram"; // this values got inserted
acc.Attributes["age"] = "22"; // this values got inserted
acc.Attributes["lookupfieldid"] = new EntityReference("contact", contactId); // if lookupfieldid is pointing to contact entity
service.Create(acc); // to create account
One consideration: you wrote
Account acc = new Account();
I don't know if you are using early bound (means the classes generated by crmsvcutil.exe
) or late bound (in this case you will write Entity acc = new Entity("account");
)
but if you use early bound, the syntax will be something like:
Account acc = new Account();
acc.Name = "Ram"; // this values got inserted
acc.Age = "22"; // this values got inserted
acc.LookupFieldId = new EntityReference("contact", contactId); // if lookupfieldid is pointing to contact entity
service.Create(acc); // to create account
using early bound you will know before the right type expected by the field.
这篇关于如何为查找字段添加值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!