Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Two value combine on one field.

Posted on by 220

Hi good day do you have any idea why the two value save on 1 text field? and that field is the default name field on the form. and what i did is i set the lookup field value to automatically map on the name field and the lookup field gets the name of the shoes and upon saving it also gets the owner of the shoes. is there a way to for example the data that is save is "NIKE, SAM SMITH" do you have any idea how to remove the owner on the name field? this is the code that ive used to automatically map the lookup field to value to the text field 

SetNameFromLookup: function () {

if(Xrm.Page.getAttribute("lookupField").getValue() != null){

var lookupField= Xrm.Page.getAttribute("lookupField").getValue()[0].name;

Xrm.Page.getAttribute("singleTextField").setValue(lookupField);
}

},

or is there a way that after i select on the lookup field it will triggered right away to mapped the data on the text field?

thanks for the help

*This post is locked for comments

  • KaeL Profile Picture
    KaeL 220 on at
    RE: Two value combine on one field.

    thank you so much. i follow the second part and now its working.

  • Suggested answer
    VermaNitin Profile Picture
    VermaNitin 455 on at
    RE: Two value combine on one field.

    Hi,

    The code your used is looks good!

    The only problem I can see is that the source field you are using to get the name value has some customization included that sets it's value as name+owner.

    So please take a look is you have some customization on that field.

    Let me know if it helps!

    Many thanks,

    Nitin Verma

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Two value combine on one field.

    Hi  Kael,

    Not sure if I understand your question correctly but if you want to combine to field value, you can simply change the code like below

    If you want to combine name field as well as the lookup you need to change the code like below

    SetNameFromLookup: function () {

    if(Xrm.Page.getAttribute("lookupField").getValue() != null){

    var lookupField= Xrm.Page.getAttribute("lookupField").getValue()[0].name;

    var nametext=Xrm.Page.getAttribute("namefieldname").getValue();

    var combinedValue=lookupField+',"+nametext; //this will combine two values

    //now you can set it to the target field

    Xrm.Page.getAttribute("singleTextField").setValue(combinedValue);

    }

    },

    Also please follow these steps to use onchange event of the field instead of form save, I think you are calling your code on save.

    Follow these setps

    1. Open form editor

    2. Double click on the lookup field

    3. Go to Events tab

    4. Click on Add under event handler and add your web resource name and method name.

    5. Save and publish your changes

    Now it will set value to text as soon as you will change value in lookup and tab out from lookup field

    I hope you have already created web resource and added it to form.

    Hope it will help

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