Wednesday, October 26, 2011

SQL SERVER - How to get Microsoft Dynamics CRM picklist Label via SQL Query (String Map CRM Table)


1. Add in your query the following Left join:


Workaround


LEFT JOIN [Organizationname_MSCRM].dbo.StringMap sm On 

sm.AttributeValue=picklistvalue AND
sm.ObjectTypeCode=3 (Example opportunity=3) AND
sm.AttributeName=''picklistname'' AND
sm.LangId=''1033'' 


2. Use sm.Value to retrieve the Picklist Label

Nicola Grillo

CRM 2011 - Use IOrganizationService in Plugin MSCRM 2011.

Following code allow connects to the Microsoft Dynamics CRM 2011 platform using the IOrganizationService Web Service.

// Comment
//use your prefered userId to get IOrganicazionService by context
private IOrganizationService getService(IServiceProvider serviceProvider, Guid userId)
        {
            IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            return serviceFactory.CreateOrganizationService(userId);
        }


Thanks,
Nicola Grillo

Thursday, October 20, 2011

CRM 4.0 - Retrieve multiple via Call MS CRM Service through Javascript


Example retrieve multiple via javascript code

var xmlcriteria = "<q1:Criteria>" +
"<q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>Attributename</q1:AttributeName>" +
" <q1:Operator>Equal</q1:Operator>" +
" <q1:Values>" +
" <q1:Value xsi:type=\"xsd:string\">" + value+ "</q1:Value>" +
" </q1:Values>" +
" </q1:Condition>" +
" </q1:Conditions>" +
"</q1:Criteria>"
var entity= RetrieveMultiple('entityname', new Array(listofattribute), false, xmlcriteria)

All Functions


Nicola Grillo 

Tuesday, October 11, 2011

CRM 4.0 - Call Microsoft dynamics CRM Service through Javascript to retrieve records (crm 4.0/2011)



//utility
function MischiefMayhemSOAP(xmlSoapBody, soapActionHeader) {
    var xmlReq = "<?xml version='1.0' encoding='utf-8'?>"
    + "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"
    + "  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
    + "  xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"
    + GenerateAuthenticationHeader()
    + "  <soap:Body>"
    + xmlSoapBody
    + "  </soap:Body>"
    + "</soap:Envelope>";
    var httpObj = new ActiveXObject("Msxml2.XMLHTTP");
    httpObj.open('POST', '/mscrmservices/2007/crmservice.asmx', false);
    httpObj.setRequestHeader('SOAPAction', soapActionHeader);
    httpObj.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
    httpObj.setRequestHeader('Content-Length', xmlReq.length);
    httpObj.send(xmlReq);
    var resultXml = httpObj.responseXML;
    var errorCount = resultXml.selectNodes('//error').length;
    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert("The following error was encountered: " + msg);
        return null;
    } else {
        return resultXml;
    }
}
// retrieve by entityId
function RetrieveRecord(entityName, entityId, attrArray) {
    var xmlSoapBody = ""
    + "    <Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"
    + "      <entityName>" + entityName + "</entityName>"
    + "      <id>" + entityId + "</id>"
    + "      <columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"
    + "        <q1:Attributes>";
    for (index in attrArray) {
        xmlSoapBody += "          <q1:Attribute>" + attrArray[index] + "</q1:Attribute>";
    }
    xmlSoapBody += ""
    + "        </q1:Attributes>"
    + "      </columnSet>"
    + "    </Retrieve>";
    var resultXml = MischiefMayhemSOAP(xmlSoapBody, 'http://schemas.microsoft.com/crm/2007/WebServices/Retrieve');
    if (resultXml != null) {
        var resultArray = new Array();
        for (index in attrArray) {
            if (resultXml.selectSingleNode("//q1:" + attrArray[index]) != null) {
                resultArray[index] = resultXml.selectSingleNode("//q1:" + attrArray[index]).nodeTypedValue;
            } else {
                resultArray[index] = null;
            }
        }
        return resultArray;
    } else {
        return null;
    }
}
//retrieve by xml criteria
function RetrieveMultiple(entityName, attrArray, distinct, criteriaXml) {
    var xmlSoapBody = ""
    + "    <RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"
    + "      <query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryExpression'>"
    + "        <q1:EntityName>" + entityName + "</q1:EntityName>"
    + "        <q1:ColumnSet xsi:type='q1:ColumnSet'>"
    + "          <q1:Attributes>";
    for (index in attrArray) {
        xmlSoapBody += "            <q1:Attribute>" + attrArray[index] + "</q1:Attribute>";
    }
    xmlSoapBody += ""
    + "          </q1:Attributes>"
    + "        </q1:ColumnSet>"
    + "        <q1:Distinct>" + distinct + "</q1:Distinct>"
    + criteriaXml
    + "      </query>"
    + "    </RetrieveMultiple>";
    var resultXml = MischiefMayhemSOAP(xmlSoapBody, 'http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple');
    if (resultXml != null) {
        var resultArray = new Array();
        var entityNodes = resultXml.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
        if (entityNodes.length > 0) {
            for (var index = 0; index < entityNodes.length; index++) {
                var entityNode = entityNodes[index];
                resultArray[index] = new Array();
                // on the 2 selectsinglenode lines with ./ (you could drop the ./ altogether if you wanted)
                for (attrIndex in attrArray) {
                    if (entityNode.selectSingleNode("q1:" + attrArray[attrIndex]) != null) {
                        resultArray[index][attrIndex] = entityNode.selectSingleNode("q1:" + attrArray[attrIndex]).nodeTypedValue;
                    } else {
                        resultArray[index][attrIndex] = null;
                    }
                }
            }
            return resultArray;
        } else {
            return null;
        }
    } else {
        return null;
    }
}

Thursday, October 6, 2011

CRM 2011 - How to add in MSCRM 2011/4.0 a new quick find Attribute (Lookup find Attribute)


Go in Customization and select entity target.

Open View section



Double click on quickfind search view

 

               
Click the button add find columns

Now you will can search the value of your attribute in the quick find box

Nicola Grillo