Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

concatenation of two string fields

Posted on by Microsoft Employee

Hi Community,

 i just try to concatenate two string fields into third field using plugin. But its not working with below code

if (entity.LogicalName == "new_tetest")

try
{
Entity test = new Entity("new_tetest");

String fname = test.GetAttributeValue<String>("new_firstname");
String lname = test.GetAttributeValue<String>("new_lastname");
string concat = fname + lname;
concat = String.Concat(fname, lname);
test["new_fullname"] = concat;
service.Create(test);


}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("invalidException", ex);
}

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: concatenation of two string fields

    Hi Chaitu ,

    If you are facing any difficulty with plugin , you can also create calculated field  for the full name .

    see below post -

    crmramblingsbysteven.wordpress.com/.../microsoft-crm-2015-how-do-i-concatenate-two-fields-in-microsoft-crm-2015-revised

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: concatenation of two string fields

    Hi Chaitu,

    You plugin code looks fine. You need to check if you have registered it correctly and if it is executing or not. You could use throw new InvalidPluginExecutionException("invalidException", ex); on the top to confirm if plugin is executing or not.

    By the way, you can achieve the concatenation by simple workflow or a calculated field-

    crmramblingsbysteven.wordpress.com/.../microsoft-crm-2015-how-do-i-concatenate-two-fields-in-microsoft-crm-2015-revised

    crmramblingsbysteven.wordpress.com/.../how-to-concatenate-two-fields-using-workflow-in-dynamics-crm-2011

    Hope this helps.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: concatenation of two string fields

    Try with this -

                            if (entity.LogicalName == "new_tetest")
                            {
                                try
                                {
                                    Entity test = new Entity("new_tetest");
                                    String fname = string.Empty;
                                    String lname = string.Empty;
                                    if (entity.Attributes.Contains("new_firstname"))
                                    {
                                        if (entity.GetAttributeValue<string>("new_firstname") != "" && entity.GetAttributeValue<string>("new_firstname") != null)
                                        {
                                            fname = entity.GetAttributeValue<string>("new_firstname");
                                        }
                                    }
                                    if (entity.Attributes.Contains("new_lastname"))
                                    {
                                        if (entity.GetAttributeValue<string>("new_lastname") != "" && entity.GetAttributeValue<string>("new_lastname") != null)
                                        {
                                            lname = entity.GetAttributeValue<string>("new_lastname");
                                        }
                                    }
                                    test["new_fullname"] = fname + " " + lname;
                                    service.Create(test);
                                }
                                catch (FaultException<OrganizationServiceFault> ex)
                                {
                                    throw new InvalidPluginExecutionException("invalidException", ex);
                                }
                            }

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: concatenation of two string fields

    Hi,

    > Are you sure your plugin is running, don't see any issue with the code,

    > Are you sure you are filling these attributes.

    Where are you checking this concatenation ?? it is creating a new record of your entity, are you not able to see any new record created for your entity having this combined value ??

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans