I really need some help from someone that is familiar with this. I have searched the forum and tried several different things, but so far, I am not getting anywhere.
I have a connection between users and I want to look up the secondary user based on the owner of the record. I ran the FetchXML test and it retrieves the correct data. When I use the javascript code below, the length is 1, so from my understanding, that means it found 1 record. However, when I try to get the record2id from the connection, it says "undefined". Please, please, please, someone tell me where I am going wrong. I have been trying to get this to work for a couple of days now. Any help would be appreciated. And I need to mention, I have to use FetchXML and not oData or anything else. I am working on someone else's code and I have to stick to their rules.
Here is the code I have so far. The code in blue is where it fails. The comments just under that are all the different things I have tried and none of them work.
function getConnection() {
var lookUpOwnerValue = Xrm.Page.getAttribute("ownerid").getValue();
if (lookUpOwnerValue != null) {
var OwnerId = lookUpOwnerValue[0].id;
var userFetchXML = lookupConnection(OwnerId);
//alert(userFetchXML);
var fetchConnectionResult = new Array();
fetchConnectionResult = XrmServiceToolkit.Soap.Fetch(userFetchXML, false);
if (fetchConnectionResult != null && fetchConnectionResult != undefined && fetchConnectionResult != 'undefined') {
if (fetchConnectionResult.length > 0) {
alert(fetchConnectionResult[0].attributes["record2id"].value);
//alert(fetchConnectionResult[0].attributes.record2id.value);
//alert(fetchConnectionResult[0].attributes["_record2id_value"].value);
//alert(fetchConnectionResult[0].attributes["_record2id_value"]);
}
}
}
}
function lookupConnection(OwnerId) {
var functionName = "lookupConnection";
var recordroleid = "82cd8858-df36-ea11-940f-005056a81a7c";
try {
var requestMain = "";
requestMain += "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
requestMain += "<entity name='connection'>";
requestMain += "<attribute name='record2id'/>";
requestMain += "<attribute name='connectionid'/>";
requestMain += "<order descending='false' attribute='record2id'/>";
requestMain += "<filter type='and'>";
requestMain += "<condition attribute='record1id' value='" + OwnerId + "' uitype='systemuser' operator='eq'/>";
requestMain += "<condition attribute='record2roleid' value='{82CD8858-DF36-EA11-940F-005056A81A7C}' uitype='connectionrole' operator='eq'/>";
requestMain += "</filter>";
requestMain += "</entity>";
requestMain += "</fetch>"
return requestMain;
} catch (e) {
alert(functionName + " >>" + e.description);
}
}
Any and all help would be greatly appreciated!