Zoeken in deze blog

maandag 17 augustus 2009

Soap: ophalen lookup uit gekoppelde entiteit

//Get the lookup ownerid

GetSalesteam = function()
{
var lookupItem = crmForm.all.ownerid.DataValue; //Dit is de de lookup waarbij je extra gegevens op wilt halen

// check if there is data in the field, get the salesteam
if(lookupItem != null && lookupItem[0] != null)
{
var sb=new StringBuilder();
sb.Append('<?xml version="1.0" encoding="utf-8"?>');
sb.Append('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/%22 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance%22 xmlns:xsd="http://www.w3.org/2001/XMLSchema%22>');
sb.Append(GenerateAuthenticationHeader());
sb.Append('<soap:Body>');
sb.Append(' <RetrieveMultiple xmlns="'+CRM2007_WEBSERVICE_NS+'">');
sb.Append(' <query xmlns:q1="http://schemas.microsoft.com/crm/2006/Query%22 xsi:type="q1:QueryExpression">');
sb.Append(' <q1:EntityName>systemuser</q1:EntityName>'); //Dit is de gekoppelde entiteit waaruit je gegevens op wilt halen
sb.Append(' <q1:ColumnSet xsi:type="q1:ColumnSet"><q1:Attributes><q1:Attribute>sgt_salesteamid</q1:Attribute></q1:Attributes></q1:ColumnSet>'); //Dit is het veld dat je uit de gekoppelde entiteit wilt ophalen
sb.Append(' <q1:Criteria>');
sb.Append(' <q1:FilterOperator>And</q1:FilterOperator>');
sb.Append(' <q1:Conditions><q1:Condition>');
sb.Append(' <q1:AttributeName>systemuserid</q1:AttributeName>');
sb.Append(' <q1:Operator>Equal</q1:Operator>');
sb.Append(' <q1:Values><q1:Value xsi:type="xsd:string">' + lookupItem[0].id + '</q1:Value></q1:Values>');
sb.Append(' </q1:Condition></q1:Conditions>');
sb.Append(' </q1:Criteria>');
sb.Append(' </query>');
sb.Append(' </RetrieveMultiple>');
sb.Append('</soap:Body>');
sb.Append('</soap:Envelope>');
var xml=sb.ToString();

var xmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.open('POST','/mscrmservices/2007/CrmService.asmx',false);
xmlHttpRequest.setRequestHeader('SOAPAction',CRM2007_WEBSERVICE_NS+'/RetrieveMultiple');
xmlHttpRequest.setRequestHeader('Content-Type','text/xml; charset=utf-8');
xmlHttpRequest.setRequestHeader('Content-Length',xml.length);
xmlHttpRequest.send(xml);
var xmlDoc=xmlHttpRequest.responseXML;
// look for response
if ( xmlDoc.selectSingleNode('//q1:sgt_salesteamid') != null ) //Controle of het veld dat je op wilt halen wel data bevat
{
var salesteam = new Array();
salesteam[0] = new LookupControlItem(
xmlDoc.selectSingleNode('//q1:sgt_salesteamid').text, 10001, //10001 is het nummer van de entiteit waaruit je gegevens op wilt halen
xmlDoc.selectSingleNode('//q1:sgt_salesteamid').getAttribute('name'));
// assign new lookup to the field
crmForm.all.sgt_salesteamid.DataValue = salesteam;
}
else
{
// make the field empty, for the contactpersoon is null
crmForm.all.sgt_salesteamid.DataValue = null;
}
}
}
GetSalesteam();

Geen opmerkingen:

Een reactie posten