Get the text data or GUID value of a lookup field with javascript code

Hi ,

in this article we talk about "Get the text data or GUID value of a lookup field with javascript code"

Sometimes, we want to learn lookup guid value and text with javascript.

Question : How can we learn this values. 
Answer : with javascript code

<script>
function learnLookupValues()
{
var lookupObject = Xrm.Page.data.entity.attributes.get("vendorID").getValue();
if(lookupObject  != null ) 
{

alert("Lookup field text" + lookupObject[0].name);
alert("Lookup field Id" + lookupObject[0].id);

}
}
</script>

let's explain the code !

Firstly, we catch up lookup field 
"

Xrm.Page.data.entity.attributes.get("vendorID").getValue();

"

then, we have to control this value 

if(lookupObject  != null )

Finally. we will use these values

alert("Lookup field text" + lookupObject[0].name);
alert("Lookup field Id" + lookupObject[0].id);

thats all 
Have a good day

Add comment