Hi! I need get values from fields. How I can do it? I'm try
Entity entity = new Entity("entity_name"); string ent = entity.Attributes["entity_name"].toString();
but not have result. Thanks!
*This post is locked for comments
It's all my code
public void Execute(IServiceProvider serviceProvider) { ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = factory.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parmameters. Entity entity = (Entity) context.InputParameters["Target"]; if (entity.LogicalName == "new_sms") { try { string number = ""; string text = ""; string parameters = ""; if (entity.Attributes.Contains("new_number")) number = entity.GetAttributeValue<string>("new_number"); if (entity.Attributes.Contains("new_text")) text = entity.GetAttributeValue<string>("new_text"); if (entity.Attributes.Contains("new_sms_parameters_smsid")) parameters = entity.GetAttributeValue<string>("new_sms_parameters_smsid"); string fetchXmlString = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='new_sms_parameters'> <attribute name='new_name' /> <attribute name='new_url' /> <attribute name='new_login' /> <attribute name='new_password' /> <attribute name='new_alphaname' /> </entity> </fetch>"; string name = ""; string url = ""; string login = ""; string password = ""; string alphaName = ""; EntityCollection ec = ExecuteFetch(fetchXmlString, service); if (ec.Entities.Count > 0) { //string output = string.Empty; foreach (var item in ec.Entities) { if (item.Attributes.Contains("new_name")) name = item.Attributes["new_name"].ToString(); if (name.Contains(parameters)) { if (item.Attributes.Contains("new_url")) //Check for fullname value exists or not in Entity Collection url = item.Attributes["new_url"].ToString(); if (item.Attributes.Contains("new_login")) //Check for fullname value exists or not in Entity Collection login = item.Attributes["new_login"].ToString(); if (item.Attributes.Contains("new_password")) //Check for fullname value exists or not in Entity Collection password = item.Attributes["new_password"].ToString(); if (item.Attributes.Contains("new_alphaname")) alphaName = item.Attributes["new_alphaname"].ToString(); } } } string single = "<message><service id='single' source=\'" + alphaName + "'/><to>" + number + "</to><body content-type='text/plain'>" + text + "</body></message>"; if (url.Contains("api.life.com.ua/ip2sms")) send(url, single, login, password); } catch { } } } } public static EntityCollection ExecuteFetch(string fetchXmlString, IOrganizationService service) { return service.RetrieveMultiple(new FetchExpression(fetchXmlString)); } //Autorization public static void SetBasicAuthHeader(WebRequest request, String userName, String userPassword) { string authInfo = userName + ":" + userPassword; authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo)); request.Headers["Authorization"] = "Basic " + authInfo; } //Send request private static string send(string Url, string Data, string login, string password) { WebRequest req = WebRequest.Create(Url); SetBasicAuthHeader(req, login, password); req.Method = "POST"; req.Timeout = 100000; req.ContentType = "text/xml"; byte[] sentData = Encoding.UTF8.GetBytes(Data); req.ContentLength = sentData.Length; Stream sendStream = req.GetRequestStream(); sendStream.Write(sentData, 0, sentData.Length); sendStream.Close(); WebResponse res = req.GetResponse(); Stream ReceiveStream = res.GetResponseStream(); StreamReader sr = new StreamReader(ReceiveStream, Encoding.UTF8); //Кодировка указывается в зависимости от кодировки ответа сервера Char[] read = new Char[256]; int count = sr.Read(read, 0, 256); string Out = String.Empty; while (count > 0) { String str = new String(read, 0, count); Out += str; count = sr.Read(read, 0, 256); } return Out; } } }
Thanks!
Unless you won't tell some details, we won't be able to help you
"Entity entity = new Entity("new_sms");
string number = "";
string text = "";
string parameters = "";
if (entity.Attributes.Contains("new_number"))
number = entity.GetAttributeValue<string>("new_number");
if (entity.Attributes.Contains("new_text"))
text = entity.GetAttributeValue<string>("new_text");
if (entity.Attributes.Contains("new_sms_parameters_smsid"))
parameters = entity.GetAttributeValue<string>("new_sms_parameters_smsid");
"
In order to get field value from the entity object first you need to get it from CRM using CRM service ?? Where are you writing this code ?? what are you trying to do ?? I don't see any code where you retrieve this information from CRM ??
I try, but not result
Entity entity = new Entity("new_sms"); string number = ""; string text = ""; string parameters = ""; if (entity.Attributes.Contains("new_number")) number = entity.GetAttributeValue<string>("new_number"); if (entity.Attributes.Contains("new_text")) text = entity.GetAttributeValue<string>("new_text"); if (entity.Attributes.Contains("new_sms_parameters_smsid")) parameters = entity.GetAttributeValue<string>("new_sms_parameters_smsid");
Try this
In java script u can get the value of the field like this
var a=Xrm.Page.getAttribute("schema name of the field").getValue();
in c# try this
entity.GetAttributeValue<String>("schemaname of the field");
If u find the answer as useful mark it as verified
Thanks
Muthuraman. E
Hi,
Could you provide some more details what you are doing, how and where you are tying to read field data ??
to get value from entities field if you have entity object it should be like below
entity.GetAttributeValue<data type>("field name")
Please download CRM SDK it has sample code or share full details here so that we can help you.
Refer this thread also:
social.microsoft.com/.../how-to-get-field-values-in-plugin-on-create-post-event
LINQ and QueryExpression will only return attributes that have a value; if an attribute is null, then it won't be included in the Entity record.
Refer this:
msdn.microsoft.com/.../microsoft.xrm.sdk.messages.retrieveentityrequest.aspx
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156