Wednesday 31 August 2011

Filtered Lookup Approaches in CRM 2011

http://gtcrm.wordpress.com/2011/03/22/filtered-lookup-approaches-in-crm-2011/


function GetCountryFromAccount() {

//Get the GUIDvalue of this Contact's Parent Account
var ParentAccount = Xrm.Page.data.entity.attributes.get("parentcustomerid");
if (ParentAccount.getValue() != null) {
var ParentAccountGUID = ParentAccount.getValue()[0].id;
}

// Read the CRM Context to determine the CRM URL
var serverUrl = Xrm.Page.context.getServerUrl()

// Specify the ODATA End Point and Entity Collection
var ODATA_ENDPOINT = "XRMServices/2011/OrganizationData.svc";
var ODATA_EntityCollection = "/AccountSet";

// Specify the ODATA Query
var ODATA_Query = "(guid\'" + ParentAccountGUID + "\')?$select=new_Country";

// Combine into the final URL
var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;

//Calls the REST endpoint to retrieve the Country value of the Parent Account
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: ODATA_Final_url,

beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},

success: function (data, textStatus, XmlHttpRequest) {
//This function will trigger asynchronously if the Retrieve was successful
var CountryGUID = data.d.new_Country.Id;
if (CountryGUID == null) {
// country on acct is null, we won't bother filtering the view
return;
}
else {
// call function to add custom view
ChangeLookupView_State(CountryGUID);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
//This function will trigger asynchronously if the Retrieve returned an error
//Error encountered, we won't bother filtering the view
return;
}
});
}

function ChangeLookupView_State(CountryGUID) {
//Set parameters values needed for the creation of a new lookup view...
var viewId = Xrm.Page.data.entity.getId(); // Your new lookup views needs a unique id. It must be a GUID. Here I use the GUID of the current record.
var entityName = "new_state"; // The entity your new lookup view relates to
var viewDisplayName = "States for Account Country"; // A name for new lookup view
var viewIsDefault = true; // Whether your new lookup view should be the default view displayed in the lookup or not

//Define the Fetch XML query your new lookup view will use. You can create this via Advanced Find. You'll need to massage the syntax a little though
var fetchXml =
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"" +
"
" +
"
" +
"
";

//Define the appearance of your new lookup view
var layoutXml =
"" +
"" + // id = the GUID field from your view that the lookup should return to the CRM form
"" +
"
" +
"
";

//Add your new view to the Lookup's set of availabe views and make it the default view
Xrm.Page.getControl("new_statelookupid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, viewIsDefault);
}

Sunday 28 August 2011

How to format a JSON date?

Eval is not necessary. This will work fine:

var date = new Date(parseInt(jsonDate.substr(6)));
The substr function takes out the "\/Date(" part, and the parseInt function gets the integer and ignores the ")\/" at the end. The resulting number is passed into the Date constructor.

Example:
(new Date(parseInt(retrievedEstimate.new_Arrowvisitationdate.substr(6)))).format("MM/dd/yyyy");

this converts /Date(1314014400000)/ to 23/08/2011

ref: http://stackoverflow.com/questions/206384/how-to-format-a-json-date

Thursday 25 August 2011

CRM Deletion Service in CRM 4.0 and CRM 2011. Asynchronize

http://www.7388.info/index.php/article/silverlight/2011-07-18/19565.html
http://blogs.msdn.com/b/emeadcrmsupport/archive/2011/06/28/crm-deletion-service-in-crm-4-0-and-crm-2011.aspx

All activities of the Deletion Service are based on table named ScaleGroupOrganizationMaintenanceJobs, which can be found in the MSCRM_CONFIG database.
You can use the following sample script to delete all records marked for deletion immediately. As direct database manipulation is not supported, this should be done only in test and not in productive environment.
--The time you set is UTC time so you need to minus 11 or 12 hours as NZ time is UTC + 12:00
USE MSCRM_CONFIG
UPDATE dbo.ScaleGroupOrganizationMaintenanceJobs
SET NextRunTime = getdate()
WHERE OperationType = 14

--To check the time for the next job to run
USE MSCRM_CONFIG
select NextRunTime
from dbo.ScaleGroupOrganizationMaintenanceJobs
where OperationType = 14

By default the SQL Server agent will trigger the job MSCRM_CONFIG.HardDelete every hour. This job will execute the stored procedure p_HardDelete, which will perform the deletion itself.

If the SQL Server Agent is not running, you have to wait on the Deletion Service itself. By default, the frequency of the Deletion Service job execution is set to once a day.

p_HardDelete is different from the Deletion Service. p_HardDelete seems to only delete internal Entities' record.

You can use the Scale Group Job Editor tool to change the execution frequency of the Deletion Service (Download here: http://code.msdn.microsoft.com/ScaleGroupJobEditor).

Possible values for the OperationType attribute can be found here:
http://msdn.microsoft.com/en-us/library/bb887932.aspx

Tuesday 23 August 2011

Model View ViewModel in WPF

Binding is an important concept in WPF implementation of the Model View ViewModel.

Step 1: Bind the UI component with data model in XAML.

Step 2: Implement the INotifyPrepertyChanged interface in the ViewModel

Reference:
http://msdn.microsoft.com/en-us/library/system.windows.data.binding.mode.aspx
http://msdn.microsoft.com/en-us/library/ms743695.aspx

This is how the View associated with the ViewModel

This is how the ViewModel associated with the Model.
The Code is in the parent ViewModel.







Thursday 18 August 2011

Microsoft Dynamics CRM 2011 User’s and Administrator’s Guides

Microsoft Dynamics CRM 2011 User’s and Administrator’s Guides

http://blogs.msdn.com/b/crm/archive/2011/08/16/microsoft-dynamics-crm-2011-user-s-and-administrator-s-guides.aspx

Tuesday 16 August 2011

CRM 2011 Development Resources

Just found this wiki with a lot of helpful dev resources for CRM 2011, the Javascript Web Resource Manager looks pretty handy!

http://social.technet.microsoft.com/wiki/contents/articles/microsoft-dynamics-crm-2011-development-resources.aspx

Sunday 14 August 2011

Increase crm time out/timeout

http://support.microsoft.com/kb/918609

If this is from CRM 2011 Online to On-Premise then make sure your SQL box has enough RAM and CPU to handle import or publish.

Three areas you can increase:
1. Web Config timeout values
2. Registry timeout values
3. SQL Timeout values

The SQL timeout update script below will increase the timeout from the default of 30.

USE MSCRM_CONFIG
GO
UPDATE DeploymentProperties
SET IntColumn=9000
WHERE ColumnName='SqlCommandTimeout'

Friday 5 August 2011

Flight against slackness - Ways to nudge yourself to do what you should do.

Scenario:
You know you should study that all the jokes and news are so attractive out there. So here is a few ways nudge yourself to do what you should do.

* Time limits - e.g. Tell yourself I have 45 min to do sth. Plus SUMMARIZE WHAT YOU HAVE DONE AT THE END.
* Make it a habit - fix the time - e.g. study between 7 pm to 11pm every Sat.

Monday 1 August 2011

Crm 4 Filtered Views empty - returns no record

That is because the windows and sql login account is not associate with a crm user with correct crm permissions