Datta,
You mean lookup Id from text?
You need to use QueryExpression, Query by Attribute, or fetchxml or Linq to retrieve this and find it using a 'where clause'
Use the text as keyword to find the lookup id.
If you use Query by Attribute:
msdn.microsoft.com/.../gg334708.aspx
Query Expression + Condition Expression or Filter Expression
msdn.microsoft.com/.../gg334419.aspx
msdn.microsoft.com/.../gg309410.aspx
It will return you Entity Collection (because it is possible to get more than 1 record by a text as keyword) you have to parse it to get only one lookupid.
If you use Linq:
msdn.microsoft.com/.../gg328028.aspx
It is an example from my code:
*It is to get the city record by name (probably same as your req)
public tfp_city GetCityInformationByName(BaseContext baseContext, string strName)
{
var cityInformation = from x in baseContext.tfp_citySet
where x.tfp_name == strName
select new tfp_city()
{
tfp_name = x.tfp_name,
tfp_CityCode = x.tfp_CityCode,
tfp_cityId = x.tfp_cityId,
};
if (cityInformation.ToList().Count > 0)
{
return cityInformation.FirstOrDefault();
}
else
{
return null;
}
Then you will return an entity record which you can get the id:
targetCity = accountBL.GetCityInformationByName(baseContext, TargetEntity.City);
Assign to your targent entity:
TargetEntity.tfp_CityId = targetCity.tfp_cityId.Value;
or if you use late bound:
TargetEntity["tfp_cityid"] = targetCity["tfp_cityid"];
If you need to assign to a lookup then you need an EntityReference
TargetEntity["tfp_cityid"] = new EntityReference("tfp_city", guidCityId);
Which guidCityId id you can get from the previous function.
You need to generate the Classes and baseContext using crmsvcutil from SDK.
What is your requirement, lookup field or option set.
Hope this helps!
Thanks.