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
Thank you for the proposed solutions. Unfortunately these are all dependent on either a valid value being saved and posted back to the database, or unsupported JavaScript. I guess we can throw all of our web standards out of the window when working with CRM, IE, SharePoint, etc....
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;
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.
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;
}
}
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.
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.
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.
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.
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;
}
}
Does this not work for lookup fields? Unless I have saved the record, the getDetails method only returns null.
André Arnaud de Cal...
291,971
Super User 2025 Season 1
Martin Dráb
230,846
Most Valuable Professional
nmaenpaa
101,156