Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Issue with retrieving Lookup field value

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

I'm new to JScript and I'm struggling with getting the correct result.

Below is code I am using to retrieve the value to the aml_ParentAccount lookup field. I have been researching and trying different scenarios for the last 3 days with no avail. I have even tried all lowercase, but also to no avail.

I am trying to set the variable Acct with the value in aml_ParentAccount. I have commented out the different scenarios I have tried, and the errors they return.

I have uploaded a screen shot of the field name to prove that I am spelling it correctly.

Can anyone help advise what the correct code is to retrieve the value from the aml_ParentAccount lookup field.

function concatTitle()
{

	var Title = Xrm.Page.getAttribute('aml_name').getValue();
	// Works - Returns the text value or null if empty.

	debugger;																// To pause code

//	var Acct = Xrm.Page.getAttribute('aml_parentaccount').getSelectedOption();
//	var Acct = Xrm.Page.getAttribute("aml_parentaccount").getSelectedOption();
	// Errors - Returns "Object doesn't support property or method 'getSelectedOption'"

//	var Acct = Xrm.Page.data.entity.attributes.get('aml_ParentAccount').getValue();
//	var Acct = Xrm.Page.data.entity.attributes.get("aml_ParentAccount").getValue();
	// Errors - Returns "Unable to get property 'getValue' of undefined or null reference"

//	var Acct = Xrm.Page.getAttribute('aml_ParentAccount').getValue();
//	var Acct = Xrm.Page.getAttribute("aml_ParentAccount").getValue();
	// Errors - Returns "Unable to get property 'getValue' of undefined or null reference"

//	var Acct = Xrm.Page.getAttribute('aml_ParentAccount');
//	var Acct = Xrm.Page.getAttribute("aml_ParentAccount");
	// Errors - Returns back null, regardless if there is a value or not.

	var TrialID = Xrm.Page.getAttribute('aml_clientprotocoltrialid').getValue();
	// Works - Returns the text value or null if empty.

}

Detailed-Research-Info-001.png

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue with retrieving Lookup field value

    Thank you Nithya,

    Even though I had tried different combinations of upper and lowercase, I must have missed doing this combination in lowercase.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Issue with retrieving Lookup field value

    Please verify your field is present on the form where you are putting this code.

    function concatTitle()
    {
    var Acct = Xrm.Page.getAttribute('aml_parentaccount')
    if(Acct != null)
    {
    alert("Field is present on form");
    var AccObjValue = Acct.getValue();
    if(AccObjValue != null)
    {
    alert("Field is not null")
    var lookupEntityType = AccObjValue[0].entityType, //To get EntityName
    lookupRecordGuid = AccObjValue[0].id, // To get record GUID
    lookupRecordName = AccObjValue[0].name; //To get record Name 
    
    if (lookupEntityType != null && lookupRecordGuid != null && lookupRecordName != null) {
    Xrm.Utility.alertDialog("Entity Type : " + lookupEntityType + "\nRecord GUID : " + lookupRecordGuid + "\nRecord Name : " + lookupRecordName, null);
    }
    }
    }
    
    }


  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Issue with retrieving Lookup field value

    Hi Kim,

    The name of the attribute you have given in the code above is aml_ParentAccount. Try to use it as aml_parentaccount  as shown below(same as the name of the attribute in the screenshot above).

    var Acct = Xrm.Page.getAttribute('aml_parentaccount').getValue();

    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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans