Thursday, December 29, 2011

CRM 2011 - Appointment plug-in in Pre-validation/Pre-creation stage with Create and Book message

If you want to registry a new plugin in CreateRequest message you have to consider that it can't be started.
Considering the following example :
You want subscribe, or register, an Appointment plug-in to the "pre-validation CreateRequest", in order to modify some appointment field.We would expect that it will run when the event occurs.

Now create a new appointment with start and end date 5 day after today.........surprise............!!!!!!! it doesn't run.
In this case the BookRequest message occurs and you have to subscrive, or register also your plug-in to BookRequest message, in order to triggering this event.

Nota:
I'm not sure but the BookRequest message should be substitute the information in the previous stage (CreateRequest in pre-validation) .

This shold be a big problem because if you want to use the Appointment plugin in ofline mode it doesn't work. Considering that the Book message work only in server mode!

In the following list you can find all appointment message :


MessageDescription
Adds recurrence information to an existing appointment to make it a recurring appointment master.
Assigns an appointment to another user or team.
Creates a link between a record and one or more records that participate in a relationship. You can also use theIOrganizationService.Associate method. For more information, seeActions on Entity Records. For a list of default relationships for this entity, see Appointment Entity Metadata.
Schedules or books an appointment.
Creates an appointment. You can also call theIOrganizationService.Create method.
Creates an exception for the recurring appointment instance,Appointment.InstanceTypeCode. For more information, seeCreate a Recurring Appointment Exception.
Deletes an appointment. You can also call theIOrganizationService.Delete method.
Removes a link between a record and one or more records that participate in a relationship. You can also use theIOrganizationService.Disassociate method. For more information, see Actions on Entity Records. For a list of default relationships for this entity, see Appointment Entity Metadata.
Shares an appointment with another security principal (user or team).
Initializes a new record from an existing record provided that an attribute map is defined for the two entities. For more information, see Customize Entity and Attribute Mappings.
Changes the access rights for an appointment previously shared with another security principal (user or team).
Reschedules an appointment.
Detects and retrieves duplicate records for the specified record, provided that duplicate detection is enabled and there are published duplicate detection rules for the entity. For more information, seeDetect Duplicate Data in Microsoft Dynamics CRM.
Retrieves an appointmentYou can also call theIOrganizationService.Retrieve method.
Retrieves a collection of appointments. You can also call theRetrieveMultiple method.
Retrieves the access that the specified security principal (user or team) has to an appointment.
Retrieves the security principals (users or teams) that have access to an appointment, together with their access rights to the appointment.
Removes all access to an appointment for the specified security principal (user or team).
Sets the state of an appointment. The possible values for this attribute are defined in the Appointment.State attribute. If you are using early bound types, you can use the AppointmentStateenumeration.
Updates an appointment. You can also call the Update method.
Validates that all the constraints of an appointment are met.



Nicola Grillo


Reference:
Microsoft Dynamics CRM 2011 SDK

Tuesday, December 20, 2011

CRM 2011 - The type initializer for 'Microsoft.Crm.LocatorService' threw an exception.

Typically the following exception :


Exception

An unhandled exception was generated during the execution of the current web request. 
Information regarding the origin and location of the exception can be identified using 
the exception stack trace below.  
The type initializer for 'Microsoft.Crm.LocatorService' threw an exception.


Appear when the iis service is down. In order to solve this problem you have to restart the service and whether an other error occured, as this:


Exception

The IIS Admin Service or the World Wide Web Publishing Service, or a service dep
endent on them failed to start.  The service, or dependent services, may had an
error during its startup or may be disabled.


You must check the related services and the disk space.


Nicola Grillo

Wednesday, November 16, 2011

CRM 2011 - How to find the Guid in CRM Data Base

If you want to find an Guid in the Microsoft Dynamics CRM Database, you should use the following query :



Query

USE <DB_NAME_MSCRM>

Declare @TN as varchar(200), @CN as varchar(200), @myValue varchar(38), @SQL as nvarchar(1000)
, @SN as varchar(200),
Create Table #myTable (Table_Name varchar(200), Column_Name varchar(200), Number_Of_Rows int)

-- Replace @myValue with the value you're searching for in the database
Set @myValue = 'Guidid' 
Declare myCursor Cursor For
Select T.Table_Name, C.Column_Name, T.Table_Schema
From INFORMATION_SCHEMA.TABLES T Inner Join INFORMATION_SCHEMA.COLUMNS C 
On T.Table_Schema = C.Table_Schema And T.Table_Name = C.Table_Name
Where T.Table_Name <> 'dtproperties' And Table_Type = 'Base Table'
And C.Data_Type In ('uniqueidentifier')
-- Replace if you want other type data
--And C.Data_Type In ('text','ntext')
--And C.Data_Type In ('tinyint','int','bigint','numeric','decimal','money','float','smallint','real','smallmoney')
--And C.Data_Type In ('datetime','dmalldatetime')
Open myCursor
Fetch Next From myCursor Into @TN, @CN, @SN
While @@Fetch_Status <> -1
Begin
                EXECUTE ( N'Insert Into #myTable Select ''' + @SN + '.' + @TN + ''', ''' + @CN + ''', Count(*) From [' + @SN + '].[' + @TN + '] Where [' + @CN + '] = CONVERT(uniqueidentifier ,''' + @myValue + ''' )')
                
                Fetch Next From myCursor Into @TN, @CN, @SN
End
Close myCursor
Deallocate myCursor
Select * From #myTable Where Number_Of_Rows > 0 Order By Table_Name
Drop Table #myTable



You should use this query in order to find also other data type.

Nicola Grillo

Wednesday, November 9, 2011

CRM 4.0 - Javascript Tooltip Description in MSCRM 4.0

// Comment
var txt="Your TXT";
document.getElementById( "attributename" ).title=txt;


Nicola Grillo

CRM 4.0 - Gathering Picklist information via SQL query in Microsoft Dynamics CRM (String Map CRM Table)


Use the following query to gathering information about CRM Picklist.


// Comment
SELECT
[ObjectTypeCode]
,[AttributeName]
,[AttributeValue]
,[LangId]
,[OrganizationId]
,[Value]
,[DisplayOrder]
,[VersionNumber]
,[StringMapId]
FROM DBNAME_MSCRM.[dbo].[StringMap]
where [AttributeName]='PicklistName'
Order by AttributeValue


Thanks,
Nicola Grillo

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

Monday, September 5, 2011

CRM 2011 - Report Parameter (Pre-Fitler Configuration )



1 Step:

Create new Parameter, like this:


Set default values :



Default values

select response0.*
from Filtered<Entityname> as response0
where (response0.statecode=0)

Now open the Report code and add or modify the following property (CustomProperty):



CODE: 




Default values


<CustomProperty>
      <Name>Custom</Name>
      <Value>
&lt;MSCRM xmlns="mscrm"&gt;&amp;lt;ReportFilter&amp;gt;&amp;lt;ReportEntity paramname="CRM_Filtered<EntityName>"&amp;gt;&amp;lt;fetch version="1.0" 
output-format=" xml-platform" mapping="logical" distinct="false"
&amp;gt;&amp;lt;entity name="<EntityName"&amp; gt;&amp; lt;all-attributes /&amp;gt;&amp;lt;filter type="and"&amp;gt;&amp;lt; condition attribute= "statecode" operator="eq" value="0" /&amp;gt;&amp;lt;/filter&amp;gt;&amp;lt;/entity&amp;gt;&amp;lt;/fetch&amp;gt;&amp;lt; /ReportEntity&amp;gt;&amp;lt;/ReportFilter&amp;gt;&lt;/MSCRM&gt;
    </Value>
</CustomProperty>

Replace all <entityname> with your logical entity name.

Nicola Grillo

Wednesday, April 27, 2011

CRM 4.0 - GenerateAuthenticationHeader Function 'Object expected' error from a Custom aspx page

This function retrieves a properly formed Microsoft Dynamics CRM authentication header. This authentication header automatically determines the appropriate authentication type to use for each deployment type: on-premise, IFD, or Microsoft Dynamics CRM Online. Note that the SOAP header for IFD does not include information about theCrmTicket because a session-based ticketing system is used.

To use this function in a custom aspx page you must insert the following code in your page:

parent.window.opener.GenerateAuthenticationHeader();

Nicola Grillo

Friday, April 8, 2011

CRM 4.0 - Message: This customer is filtered due to AntiSpam settings., ErrorCode: -2147220699



The Anti-Spam Setting excludes records that have been contacted within the specified number of days.
Set 0 in anti-spam setting (Form Campaign Activity).



Nicola Grillo

Wednesday, March 16, 2011

CRM 2011 - Get and set Java Script Microsoft CRM 2011

Xrm.Page.getAttribute('statuscode').getValue()
Xrm.Page.getAttribute('statuscode').setValue(1)


Set value in picklist type :
Xrm.Page.getAttribute('statuscode').setValue(1).getSelectOption().text


Nicola Grillo

Friday, February 18, 2011

SQL SERVER - Database Suspected in SQL Server 2008

Connected to your database and check if it is in emergency mode, else run this comand:
ALTER DATABASE DB_NAME SET EMERGENCY
set single user in the database property and run this command:
DBCC CHECKDB ('DB_NAME',REPAIR_ALLOW_DATA_LOSS)

Nicola Grillo

Tuesday, January 11, 2011

CRM 4.0 - Assign entity using Javascript CRM 4.0


function assign(userid,recordid){
  var header = GenerateAuthenticationHeader();

  var target = "TargetOwned<Entityname>";
  var xml = "" +
  "<?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\">" +
  header +
  "  <soap:Body>" +
  "    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
  "      <Request xsi:type=\"AssignRequest\">" +
  "        <Target xsi:type=\""+ target +"\">" +
  "          <EntityId>"+ recordid +"</EntityId>" +
  "        </Target>" +
  "        <Assignee>" +
  "          <PrincipalId xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">"+ userid +"</PrincipalId>" +
  "          <Type xmlns=\"http://schemas.microsoft.com/crm/2006/CoreTypes\">User</Type>" +
  "        </Assignee>" +
  "      </Request>" +
  "    </Execute>" +
  "  </soap:Body>" +
  "</soap:Envelope>" +
  "";
  var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
  xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
  xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
  xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
  xmlHttpRequest.send(xml);

  var resultXml = xmlHttpRequest.responseXML;

 }


Nicola Grillo