Friday, September 30, 2011

Filtered Lookup OK Button disabled.

I was, facing a weird issue in the filtered lookup configured through the JavaScript.

This is what the issue was: I was, able to see the filter happening, But, when I open a look up, the OK button to select one, was disabled.

Solution: In the Layout Xml, I had a different Id field of another entity (Please, fallow the below line of code to find an ID). Also, if you make any typo while defining an Id field, you will face this issue (OK button disabled).
"" +

Hope, this helps.

Object Type Code in CRM 2011

Below, is the sample to get the Object Type code from the CRM 2011. Since, the object type code can be easily found from the entity record, which, may not be same in the other environment when you import the solution. We can fetch the Object Type code dynamically from the sample as in the below code.

var getObjectTypeCode = function(entityName) {
var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
lookupService.SetParameter("entityName", entityName);
var result = lookupService.Execute();

if (result.Success && typeof result.ReturnValue == "number") {
alert(result.ReturnValue);
return result.ReturnValue;
} 
else {
return null;
}
}

You may not find the "RemoteCommand" in the SDK, But, internally this has been in use in CRM 2011. More information to fallow...

Thursday, September 29, 2011

Using Fetch Expression from the Plug in code. CRM 2011

Fallowing, are the steps that we can make use of while executing the Fetch XML query.

1) Create a fetch xml query with the help of Advanced find option and format as in the below code

2) Call service.RetrieveMultiple and pass on the Fetch Xml query to the Fetch expression as in the below code. This should give you the result.

string fetchAccountType = @""+
""+ 
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       ""+
       //Passsing a parameter (accountId) to the fetch xml query
       "" +
       ""+
       ""+
       ""+
       ""+
       "";
                var entityCollection = service.RetrieveMultiple(new FetchExpression(fetchAccountType));
                string accountType = string.Empty;
                if (entityCollection.Entities.Count > 0)
                    if (entityCollection.Entities[0].Attributes.Contains("new_name"))
                        accountType = entityCollection.Entities[0].Attributes["new_name"].ToString();