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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Problem getting data from multiline memo filed

(1) ShareShare
ReportReport
Posted on by 1,589

I have a form in CRM 2011 that contains a multi-line MEMO field.

I have a plugin that is supposed to get the data contained in that memo field.

I have a line of code that is supposed to retrieve the contents of the multiline memo box.

var AdditionalInformationPri = GetFieldStringData(service, localContext, new_s_checkstaging, "new_additionalInformationpri");


The procedure GetFieldStringData, that the code from above uses, is shown below.

 protected string GetFieldStringData(IOrganizationService EntityService, LocalPluginContext EntityLocalContext, Entity PassedEntity, string PassedField)
        {
            IPluginExecutionContext context = EntityLocalContext.PluginExecutionContext;

            EntityService = EntityLocalContext.OrganizationService;

            ITracingService TracingSvc = EntityLocalContext.TracingService;

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                PassedEntity = (Entity)context.InputParameters["Target"];
                //Entity new_s_testentity = (Entity)context.InputParameters["Target"];

                try
                {

                    var postImage = context.PostEntityImages["PostImageAddImportCheckToCheckRegister"];
                    PassedEntity = postImage;

                    var MyFieldValue = PassedEntity.GetAttributeValue<string>(PassedField);
                    
                    if (String.IsNullOrEmpty(MyFieldValue))
                    {
                        try
                        {
                            var result = "NULL";
                            return result;
                        }
                        catch (Exception ex) { throw new Exception("Error in IF/TRY TransactionID Check: " + ex.Message); }
                    }
                    else
                    {
                        try
                        {
                            var result2 = MyFieldValue;
                            return result2;
                        }
                        catch (Exception ex) { throw new Exception("Error in ELSE/TRY TransactionID Check: " + ex.Message); }

                    }
                }

                catch (Exception ex) { throw new Exception("Error in GetFieldStringData: " + ex.Message); }

            }
            return null;
        }

This works great with getting the value of single line text box items, but for some reason it's returning a null or empty when it executes against a record that has 2 lines of text in the memo field..

What am I doing wrong? There will be anywhere from 0 to 20 lines of text in this memo field. The specific record I am using as an example has 2 lines of text. Yet a value of null or empty is being returned instead of the expected text that's in there.

I am probably missing something in the code below.

If anyone can take a quick look and let me know what I am missing, that would be greatly appreciated.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Frankly your code is horrible.

    You are passing an entity to a function, then you set it as target image, then again you set it as post image.

    At the end you just need to get the value from the post image.

    Simple 2 liners will do

    var postimage = context.PostEntityImages["PostImageAddImportCheckToCheckRegister"];

    var value = postimage.getAttributeValue<string>(PassedField);

  • ACECORP Profile Picture
    1,589 on at

    The code below produces a null or empty value for MyFieldValue. That's the problem. There is text in the memo field. Several lines of it. Why is it not being returned? That's what I need to understand.

    var postImage = context.PostEntityImages["PostImageAddImportCheckToCheckRegister"];

    var MyFieldValue = postImage.GetAttributeValue<string>(PassedField);

  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    likely the image does not contain that field, check the image registration using plugin registration tool

  • Verified answer
    Community Member Profile Picture
    on at

    Recheck the few things:

    1.Image name is correct, are you able to get postimage object?

    2.Field name is correct, all small case. check the field is included in the image.

  • ACECORP Profile Picture
    1,589 on at

    Apparently, I misspelled the field name and it was very close to another field name I was working with. My bad. Thanks for helping me zero in on that.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans