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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting Text Value w/ JavaScript

(0) ShareShare
ReportReport
Posted on by

Is there a supported way to get the text value of a field within CRM?  For instance, I want to know if the user has entered any text in a field before I execute a function, so I would normally check via:

var toUserText = document.getElementById('to_ledit_multi').value;

However, I understand that this is not supported in CRM.  Is there a supported way to get the text value?  I know I can get the actual saved value, but that is not what I am looking for here.  Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Pramod M Profile Picture
    1,445 on at

    You can get the value by

    Xrm.Page.getAttribute(“to_ledit_multi”).getValue() ;

    You can refer the following page for more details.

    crmbusiness.wordpress.com/.../crm-2011-javascript-xrm-page-basics

  • Community Member Profile Picture
    on at

    Does this not work for lookup fields? Unless I have saved the record, the getDetails method only returns null.

  • Suggested answer
    Pramod M Profile Picture
    1,445 on at

    For Lookup

    var lookupObject = Xrm.Page.getAttribute("to_ledit_multi");

       if (lookupObject != null)

     {

           var lookup = lookupObject.getValue();

           if ((lookup != null))

           {

            var lookuptextvalue = lookup[0].name;

            var lookupid =lookup[0].id;

           var type = lookup[i].entityType;

           }

     }

  • Community Member Profile Picture
    on at

    Is there a supported way to get the text value of a field within CRM?  For instance, I want to know if the user has entered any text in a field before I execute a function, so I would normally check via:

    var toUserText = document.getElementById('to_ledit_multi').value;

    However, I understand that this is not supported in CRM.  Is there a supported way to get the text value?  I know I can get the actual saved value, but that is not what I am looking for here.  Thanks.

  • Pramod M Profile Picture
    1,445 on at

    Hi,

    Xrm.Page.getAttribute('your textbox name').getValue() should give you the current value which is entered in text box, if your current text box value is different from saved value.

    Please let me know if this helps you.

  • Community Member Profile Picture
    on at

    I have tried this, and it works great the first time I enter a value.  However, if I remove that value and type a new value, the name of the text box control changes from 'to_ledit_multi' to "to_i_ledit_multi" and 'to_ledit_multi' is no longer accessible on the page, which causes an error to be thrown.  I understand that I can defensively code around this error, but that seem rather hack-ish, and not knowing when or what MS will change the control id to next is unsettling.  I was under the assumption that this is the main reason for Microsoft not supporting coding to actual DOM elements in CRM, but I don't see an obvious means of extracting the actual text value of a page element with the Xrm tools.

  • Pramod M Profile Picture
    1,445 on at

    what filed you are trying to get the value? are you using crmtext box or a lookup?

    And can you please post your code here so that I can help you.

  • Community Member Profile Picture
    on at

    I am trying to get the text value of the "To" lookup on the "Phone Call" activity form.  Below is the code that I am using to do so, which does not provide the text value.  I have also tried to get the text value of the actual HTML element 'to_ledit_multi' which is the name of the input element associated with the 'To" lookup on the form and which is apparently an ephemeral element:

    function addLookupFilter() {

       var lookupTextValue;

       var toUser = Xrm.Page.getAttribute('to');

       if (toUser != null) {

           var lookup = toUser.getValue();

           if (lookup != null) {

               lookupTextValue = lookup[0].name;

           }

       }

  • Pramod M Profile Picture
    1,445 on at

    The below code gives you selected valid values from a multi lookup ('To' lookup).

    var ToFielValue = Xrm.Page.getAttribute('to');

    // var Textvalue =ToFielValue.controls.$5_0[0].$2_0[0].innerText

    var ToDetails = ToFielValue.getValue();

    for (var indxTo = 0; indxTo < ToDetails.length; indxTo++) {

       alert('selected value - ' + ToDetails[indxTo].id + ' Name -' + ToDetails[indxTo].name);

    }

    Since there are multiple values you need to loop through the object to get all the data.

    This will work if you change data values also if the lookup is able to resolve the values, if there is an invalid value you need to remove the same from the lookup before you get the updated value( this invalid values are shown in red color).

    There are ways to get text value of the lookup. The commented line in the above code gives you the control value but you need to manipulate the text received to get the data (simple to do). But I think these will be unsupported way of getting data.

    So the best way is to get data using above supported code.

    Hope this helps.

  • Shh Profile Picture
    on at

    To get the value of the lookup you can do by this way

    var LookupID = Xrm.Page.data.entity.attributes.get("lookupfieldname").getValue()[0].id;

    var LookupText = Xrm.Page.data.entity.attributes.get("lookupfieldname").getValue()[0].name;

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans