web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How I can retrieve values from fields?

(0) ShareShare
ReportReport
Posted on by

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!

_1104350437044B043C044F043D043D044B043904_.png

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at

    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

  • Rajkumar Rajaraman Profile Picture
    on at

    Refer this thread also:

    social.microsoft.com/.../how-to-get-field-values-in-plugin-on-create-post-event

  • Mahendar Pal Profile Picture
    45,095 on at

    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.

  • Community Member Profile Picture
    on at

    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

  • Community Member Profile Picture
    on at

    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");


  • Mahendar Pal Profile Picture
    45,095 on at

    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 ??

  • Community Member Profile Picture
    on at

    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!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans