Reputation: 57
I want to get values from these attributes:
class Program
{
private static OrganizationService _orgService;
private static void Main(string[] args)
{
ClientCredentials cre = new ClientCredentials();
cre.UserName.UserName = "login";
cre.UserName.Password = "password";
Uri serviceUri = new Uri("some_adress");
OrganizationServiceProxy proxy = new OrganizationServiceProxy(serviceUri, null, cre, null);
proxy.EnableProxyTypes();
IOrganizationService service = (IOrganizationService) proxy;
retrieveEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.All,
LogicalName = "new_sms_parameters",
RetrieveAsIfPublished = true
};
retrieveEntityResponse = (RetrieveEntityResponse) service.Execute(retrieveEntityRequest);
currentEntity = retrieveEntityResponse.EntityMetadata;
// Attributes
foreach (AttributeMetadata allattributes in currentEntity.Attributes)
{
Console.WriteLine("SMS Parameters: " + allattributes.LogicalName);
}
}
}
Here I connect to CRM and get attributes name, but I not have an idea how I can get these values. What can I do next?
Upvotes: 1
Views: 1179
Reputation: 17562
RetrieveEntityRequest
is for getting metadata that describes an entity, for example; number of fields, types of field, like string, int, etc.
If you want to get record information you need to use Retrieve to get a single record by Id, or RetrieveMultiple to get multiple records based on a query.
Check the links above for full examples, but effectively:
ColumnSet attributes = new ColumnSet(new string[] { "name", "ownerid", "address1_postalcode" });
account = service.Retrieve(account.LogicalName, accountId, attributes);
String postcode = account["address1_postalcode"];
String alsoPostcode = account.GetAttributeValue<String>("address1_postalcode");
Upvotes: 1