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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Copy data from one field to another within the same entity but of different type

(0) ShareShare
ReportReport
Posted on by 87

Hi,

is it possible to (automatically) copy a field value from a lookup/search field to another field of type single text?

I.e. field value from productid to a newly created single text field

Thanks in advance

*This post is locked for comments

I have the same question (0)
  • Dick_Darlington Profile Picture
    87 on at
    RE: Copy data from one field to another within the same entity but of different type

    Hi all,

    one more thing...

    is it possible to load the quotedetail form automatically after selecting an existing product (productid) just like when you chose a manual product (productdescription)?

    productid02.JPG

    productid02.JPG

    productid03.JPG

  • Dick_Darlington Profile Picture
    87 on at
    RE: Copy data from one field to another within the same entity but of different type

    Hi,

    well...it's pretty weird...sometimes the OnLoad events are OK and sometimes not. OnSave on the other hand is always processed properly.

    There is no business rule in place that could cause that issue. Due to the fact that this issue is not too bad at all in this scenario I'm Ok with the success of the OnSave event :-)...

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Copy data from one field to another within the same entity but of different type

    Is it possible that you have another field which is updating the productid field?

    Something has to trigger a change. Once a value is set, it should not disappear, unless you have some business rules that do not allow a particular value.

    You can try and see what gets called after your On Change event, by using your browser developer tools (F12).

    What is your onLoad doing? What functions is it calling?

  • Dick_Darlington Profile Picture
    87 on at
    RE: Copy data from one field to another within the same entity but of different type

    One more issue...when I set this script as an OnLoad event to the form, the value is set to the the field and then gets deleted after a few milliseconds :-O...

    There is no other business rule or event or anything that could do this.

    Why might this happen?

  • Dick_Darlington Profile Picture
    87 on at
    RE: Copy data from one field to another within the same entity but of different type

    THX, you're awesome ;)!!!!

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at
    RE: Copy data from one field to another within the same entity but of different type

    Add the following code to your JavaScript file:

    function vorhandenesProduktOnChange()

    {

      var vorhandenesProdukt = getLookupName("productid");

      if (vorhandenesProdukt != '')

         Xrm.Page.getAttribute("eura_produkt").setValue(vorhandenesProdukt); // notice No Quotes

      else

         Xrm.Page.getAttribute("eura_produkt").setValue("");

    }

    function getLookupName(fieldName) {

       var field = Xrm.Page.getAttribute(fieldName);

       if (field != null) {

           var fieldId = field.getValue();

           if (fieldId != null)

               return fieldId[0].name.toString();

           else

               return '';

       }

    }

    Hope this helps.

  • Dick_Darlington Profile Picture
    87 on at
    RE: Copy data from one field to another within the same entity but of different type

    Hi all,

    I have never done anything using javascript in Dynamics CRM...:-D...

    I tried to add this javascript to the lookup field:

    var vorhandenesProdukt = Xrm.Page.getAttribute("productid").getValue();

    Xrm.Page.getAttribute("eura_produkt").setValue("vorhandenesProdukt");

    Result:

    4477.z.JPG

    value vorhandenesProdukt is being set to the field eura_produkt but not the lookup value SME-Phase-II

     

    Plus there's an error message when I change the value of productid:

    ReferenceError: eura_set_productdescription is not defined
        at eval (eval at RunHandlerInternal (eura-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1)
        at RunHandlerInternal (eura-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx)
        at RunHandlers (eura-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx)
        at ExecuteHandler (eura-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx)
        at Mscrm.TurboForm.Control.CustomScriptsManager.$CW_1 (eura-sandbox.crm4.dynamics.com/.../formcontrols.js)
        at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandler (eura-sandbox.crm4.dynamics.com/.../formcontrols.js)
        at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandlerByDescriptor (eura-sandbox.crm4.dynamics.com/.../formcontrols.js)
        at eura-sandbox.crm4.dynamics.com/.../formcontrols.js
        at eura-sandbox.crm4.dynamics.com/.../global.ashx
        at Mscrm.TurboForm.Control.Data.LookupDataAttribute.fireOnChange (eura-sandbox.crm4.dynamics.com/.../formcontrols.js)

     

     

    Field properties look like this:

    4477.z.JPG

    What am I doing wrong :-D?

    Thank you very much!

     

  • VermaNitin Profile Picture
    455 on at
    RE: Copy data from one field to another within the same entity but of different type

    Hi,

    Yes, it is possible to set a text field value based on a lookup reference.

    There are multiple approaches to achieve this like script (Run-time changes on client side), Workflow and Plugin(Server Side).

    Based upon your scenario you can choose the best suited option.

    Script:

    https://msdn.microsoft.com/en-us/library/jj602964.aspx#BKMK_EntityAttributeData

    Workflow:

    https://technet.microsoft.com/en-in/library/dn531057.aspx#BKMK_ActionsWorkflowProcessesCanPerform

    Plugin:

    https://www.magnetismsolutions.com/blog/roshanmehta/2012/07/19/setting_values_programmatically_via_the_crm_2011_sdk

    Hope it helps!

    Many thanks,

    Nitin Verma

     

  • TNS Profile Picture
    1,197 on at
    RE: Copy data from one field to another within the same entity but of different type

    Hi,

    you can write a javascript at on change of your look up field, where you can find the text from your look up field and set the value into in your text field.

    Thanks!

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans