Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Concatenate two fields- Look up and date field into a text field

Posted on by 80

Hi,

I have a requirement to Concatenate look up field and date field into a text field.  We are doing this with an out of box work flow

“Name”: . Value must be ‘First Name’ + “ “ + ‘Date of Birth’

First Name: ABC

DOB: 11/11/1981

Name : ABC 11/11/1986 12:00 AM

20602.Capture.PNG

We don't need to display the time in the NAME field. Could anyone tell us how to get rid of time?

*This post is locked for comments

  • Suggested answer
    Drew Clark Profile Picture
    Drew Clark 75 on at
    RE: Concatenate two fields- Look up and date field into a text field

    Try this JavaScript below and checkout my blog post on concatenating in dynamics, It will show you how to add this JavaScript as a web resource and get it up and running! Please let me know if this works!

    www.clarkandali.com/.../concatenate-in-dynamics-365-with-javascript

    //Concatenate Name and formatted DOB into one field

    function ConcatenateName() {

    //Create a variable for First Name, and DOB

    //Name the variables sensibly and set them equal to the field's logical name

    var name = Xrm.Page.getAttribute("new_firstName").getValue();

    var dob = Xrm.Page.getAttribute("new_dob").getValue();

    //Format the date value from CRM to Day/Month/Year

    var day = dob.getDate() + "";

    var month = (dob.getMonth()+1) + "";

    var year = dob.getFullYear() + "";

    if (dob != "" && dob != null) {

       dob += day + "/" + month + "/" + year;

    }

    //Create a variable to contain the concatenated values

    var nameAndDate = "";

    //Create conditional checks for blank or null values

    if (name != "" && name != null) {

    //Add the name value to the nameAndDate variable

    //Add a space afterwards

    nameAndDate += name + " ";

       }

    //Repeat the conditional checks for Date of birth

    if (dob != "" && dob != null) {

    nameAndDate += dob;

       }

    //push the concatenated value into the field on the form

    //replace new_nameAndDate with the logical name from the form

    Xrm.Page.getAttribute("new_nameAndDate").setValue(nameAndDate);

    }

  • Suggested answer
    RE: Concatenate two fields- Look up and date field into a text field

    Thanks!

  • Drew Poggemann Profile Picture
    Drew Poggemann 9,079 on at
    RE: Concatenate two fields- Look up and date field into a text field

    Sorry, I misread the question.  Nice reply Prashant!

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: Concatenate two fields- Look up and date field into a text field

    Hi

    I would suggest you to do the following:

    Step 1: Hide your field called 'Name' on form (the one which you have mentioned in ur post)

    Step 2: Leave your workflow as it is

    Step 3: Create one more field, Text and calculated and call it 'Name 2' or whatever you want (If u want to know more on how to create calculated field, read [View:http://www.encorebusiness.com/blog/dynamics-crm-calculated-fields/:750:50])

    Click on edit, as shown below:

    51850.2.PNG

    Set formula (copy what I have shown below)

    51850.2.PNG

    Save and close, place the field on form and publish customizations

    Now check, you will be able to get rid of time value.

    To know more about trimleft or trimright function read http://www.powerobjects.com/2015/11/06/use-trimleft-or-trimright-in-calculated-fields/ 

  • Suggested answer
    Drew Poggemann Profile Picture
    Drew Poggemann 9,079 on at
    RE: Concatenate two fields- Look up and date field into a text field

    Hi AXCRM1,

    You can set this through a workflow, I verified this and it worked successfully.  I did the following:

    1.  I setup a real time workflow on a test entity

    2.  I fired the workflow on the change of the name field

    3.  Steps

       a.  Step 1 - Update record to set text field to the Name field value and a space

       b.  Step 2 - Updated record to "Append" the createdon date field

    When I changed the name it saved it correctly with the two field concatenated so I assume it would work fine as well with a day of birth type field.

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Concatenate two fields- Look up and date field into a text field

    you will need a custom javascript, custom workflow activity or a plugin in order to hide the time (the way depends on your exact requirement)

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans