Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

Mapping fields by First Name and Last Name when a record isn't found on Contact

Posted on by 45

When a search doesn't shows results I want to take this text and put on First Name and Last Name on a New Quick Contact

Is possible?

contacto-1.PNG

contacto-2.PNG

Thanks

Categories:
  • neryhumberto Profile Picture
    neryhumberto 45 on at
    RE: Mapping fields by First Name and Last Name when a record isn't found on Contact

    Hi Ravi thanks for your help, I change the code and it works fine, I wonder if you would like to give me just your opinion of this problem that I dont have any idea how to solve without changing all my unique code for my clients..

    More details...

    community.dynamics.com/.../957111

    Thank you.

    ------------------------------------------

    function loadsearchResults() {

      try {

          var searchResults = Xrm.Page.getAttribute("lastname").getValue();

          var searchName = searchResults.split(" ");

          Xrm.Page.getAttribute("new_primernombre").setValue(searchName[0]);

          Xrm.Page.getAttribute("new_primerapellido").setValue(searchName[1]);

          Xrm.Page.getAttribute("lastname").setValue(searchName[1]);

      }

      catch (err) {

          console.log(err.message);

      }

    }

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping fields by First Name and Last Name when a record isn't found on Contact

    The logic seems correct. If you remember, CRM automatically puts the value in the last name field. So you need to run this code on Contact On Load, get the value from the last name field, split the value and then set it as per your requirement.

    By the way, do you have your custom field for firstname and last name because contact field name are firstname & lastname

  • neryhumberto Profile Picture
    neryhumberto 45 on at
    RE: Mapping fields by First Name and Last Name when a record isn't found on Contact

    Hi Ravi,

    I made this code, and doesn't do anything when I create a new contact, I load it onLoad form of Quick Contact, sorry I new on JS


    "new_contacto" is the lookup field of Contact on the main form, in this field is where I search the name and last name.
    "new_primernombre" is the field in Contacts entity where I want to paste the "First Name" value.
    "new_primeapellido" is the field in Contacts entity where I want to paste the "First of Last Name" value

    function loadsearchResults() {

    try {

    var searchResults = window.top.frames[0].Xrm.Page.getAttribute("new_contacto").getValue();

    var searchName = searchResults.split(" ");

    Xrm.Page.getAttribute("new_primernombre").setValue(searchName[0]);

    Xrm.Page.getAttribute("new_primerapellido").setValue(searchName[1]);

    }

    catch (err) {

    console.log(err.message);

    }

    }

    searchresults.png

    searchresults2.png

    Thanks

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping fields by First Name and Last Name when a record isn't found on Contact

    As mentioned above, you can add a JS code on load to split based on either of the option specified above i.e split and put last as last name or split and put first as first name.

    Let me know what you want and I will  see if I code share any sample code with you.

  • neryhumberto Profile Picture
    neryhumberto 45 on at
    RE: Mapping fields by First Name and Last Name when a record isn't found on Contact

    Hi Ravi

    In the case the name is just Ravi Kashyap, one name and one last name. how I can do it in javascript ?

    Take the value what I am searching and slipt this value on a new quick contact.

    Thanks

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Mapping fields by First Name and Last Name when a record isn't found on Contact

    Hi,

    It happens automatically however it puts the full text into last name field. As it is not easy to separate first name & last name logically i.e. If the name is Ravi Kumar Kashyap, you would not know if Ravi needs to go to first name or Ravi Kumar.

    However if you decide and confirmed the name split approach like

    1) Take the first bit i.e. before space, put in in first name and put everything else on the last name. Or

    2) Take the last bit i.e. after last space, put in in last name and put everything else on the first name.

    Then you can add a JavaScript code on the load of your contact which checks if the form is create and last name contains data, then split the name and put it based on any of the above logic.

    Hope this helps.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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