Zoeken in deze blog

woensdag 26 augustus 2009

Creëer masker op veld

function OnCrmPageLoad()
{
Mask( "telephone2" , "+(###)-(#)###-###" );
Mask( "gi_visa" , "####-####-####-####" );
Mask( "gi_scid" , "#-########-#" );
}

function Mask( fieldId , mask )
{
field = document.getElementById(fieldId);
field.mask = mask.split("");
field.regex = new RegExp(escapeRegEx(mask.replace(/#/gi,"").split("")),"gi");
field.title += " " + mask;
field.attachEvent( "onchange" , MaskOnFieldChange );
}

function escapeRegEx( chars )
{
var regChars = "+_)(*^$[]-?{}"; //Add all regexp chars id needed
var regExprs = "";
var run2Index = chars.length - 1;

for( var i = 0 ; i < run2Index ; i++ ) Concat( chars[i] , "|" );

Concat(chars[run2Index]);

function Concat( c , d ){
regExprs += (( regChars.indexOf(c) != -1 )? "\\":"" ) + c + d;
}

return regExprs;
}

function MaskOnFieldChange()
{
var field = event.srcElement;
if( field.DataValue == null ) return;

var arrDataValue = field.DataValue.replace(field.regex,"").split("");
var arrResult = [];

for(var i=0 , j=0 ; i < field.mask.length ;i++)
arrResult[i] = (field.mask[i] != "#")?field.mask[i]:arrDataValue[j++];

field.DataValue = arrResult.join("");
}

OnCrmPageLoad();

Opvragen fetch vanuit Advanced Find

javascript:void( new function(){ prompt("Fetch Parameters:",getFetchParams());function getFetchParams(){ return "FetchXml:\n" + advFind.FetchXml + "\n\n" + "LayoutXml:\n" + advFind.LayoutXml + "\n\n" + "EntityName:\n" + advFind.EntityName + "\n\n" + "DefaultAdvancedFindViewId:\n" + advFind.DefaultAdvancedFindViewId } } )

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();