Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Set Value in a LookUp

$
0
0

I'm using CRM 2016 Update 2 [Online]. The version of XrmServiceToolkit 2.2.1. All the values are displayed correctly in the alert but it's not populating the lookup field. What am I missing?

Here is my code:

function TestOnLoad() {

var Getlookup = Xrm.Page.getAttribute("TestText").getValue()[0].id;
var FetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical'>" +
"<entity name='entityName'>" +
"<attribute name='Attribute1' />" +
"<attribute name='Attribute2' />"+
"<filter type='and'>" +
"<condition attribute='Attributeid' operator='eq' value='" + Getlookup + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
var Result = XrmServiceToolkit.Soap.Fetch(FetchXML);
if(Result.length > 0) {
if (Result[0].attributes.Attribute1!= undefined) {
var fieldName = "LookupFieldName"; // *** fieldName = The name of the lookup field
var fieldType = Result[0].logicalName; // *** fieldType = The type of field (contact, account etc)
var fieldId = Result[0].attributes.Attribute1.id; // *** fieldId = The ID of the value to set (GUID)
var value = Result[0].attributes.Attribute1.name;// *** value = the value(name) to set

alert(fieldName);
alert(fieldType);
alert(fieldId);
alert(value);


SetLookUp(fieldName, fieldType, fieldId, value)
}
}
}
function SetLookUp(fieldName, fieldType, fieldId, value) {
try {
var object = new Array();
object[0] = new Object();
object[0].id = fieldId;
object[0].name = value;
object[0].entityType = fieldType;
Xrm.Page.getAttribute(fieldName).setValue(object);
}
catch (e) {
alert("Error in SetLookUp: fieldName = " + fieldName + " fieldType = " + fieldType + " fieldId = " + fieldId + " value = " + value + " error = " + e);
}
}


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>