Friday 25 May 2012

Metadata documentation

Error registering plugins and/or workflows

Created a plugin and created a key and signed the project with that key, when deploying getting following error


"Error registering plugins and/or workflows. Public Assembly must have public key"


When checking in the crm exprlorer the plugin is registered correctly.


It was happening due to not registering the workflow project with the signed key, either remove the project if not required, otherwise deployment process also trying to deploy both plugin and workflow assembly.

Thursday 24 May 2012

how to reload a page

On entity form load i am showing a user dialog to select some values, and on completion of that dialog I am trying user to see the selection he made on the dialog are reflected on the entity form.

as there is no changes done on any attriubte using javascript, calling Xrm.Page.data.entity.save() is not gonna work.

Tried using Xrm.Page.getAttribute("new_attribute1").setValue(Xrm.Page.getAttribute("new_attribute1").getValue());
 Xrm.Page.getAttribute("new_attribute1").setSubmitMode("always");

The above couple of code lines will not work either, the reason is that though I am trying to use setSubmitMode("always"), still the data entity is not dirty,

so here is code i used make sure the page is reload by force, this following code is already with in many conditions so this code is reached when I need to reload page.

In my understanding setSubmitMode("always") is used to save a value of read only fields, or when we are making some changes on attribute and like to force entity to save.



        if (Xrm.Page.data.entity.getIsDirty()) {

            Xrm.Page.data.entity.save();

        } else {

            window.location.reload(true);

        }




/////////////////
in another scenario I wanted to save some of the values which i calculated using javascript, when there were some mandatory fields on the form are not populated and we don't like use at that moment of time to save values.




function ClearRequiredFields () {
        if (!Xrm.Page.data && !Xrm.Page.data.entity) {
            return;
        }
        var attributes = Xrm.Page.data.entity.attributes.get();
        for (var i in attributes) {
            var attribute = Xrm.Page.getAttribute(attributes[i].getName());
            if (attribute.getRequiredLevel() == "required" && !attribute.getValue()) {
                attribute.setRequiredLevel("none");
            }
        }
    }

Tuesday 22 May 2012

CRM interface customisation

http://msdn.microsoft.com/en-us/library/gg328217.aspx

On CRM Entity Navigation Area we can not add new navigation groups or remove existing one. To change the group name, select group and click on properties ribbon button.

To customise ribbon button, creating new ribbon button, hiding or un-hiding existing default crm buttons use Visual Ribbon Editor from http://crmvisualribbonedit.codeplex.com/

To customise sitemap use the SiteMap Editor which can be downloaded from

http://sitemapeditor.codeplex.com/releases/view/87898


For icons have a look at http://www.iconfinder.com/


Wednesday 16 May 2012

Dangling Entity

In org1 I created a solution with entity A, and imported it as a managed solution in org2, in org 2 I created an entity C and created a relation to entity A, later on I deleted entity A from org1 and reimported the managed solution from org1 to org2. 

The entity A still exists in org2 as it has a relation with entity C, I deleted the relationship and now I am left with a dangling entity A in org2, I can not deleted in org2 as its a managed entity imported from different org's solution. and now this entity no longer exists in org2.

The only thing I done is changed its display name to be bit descriptive saying it is no longer valid and shouldn't be used in org2.

Friday 4 May 2012

Custom activity Expected non-empty Guid

When writing custom activity for dialog process, I was getting an error " Expected non-empty Guidif I don't set the Out Argument of EntityReference type. Though the custom activity code is executing fine, this error was coming from with the workflow engine, Here is the complete error message


Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Expected non-empty Guid.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
  <ErrorCode>-2147220989</ErrorCode>
  <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>CallStack</d2p1:key>
      <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">   at Microsoft.Crm.Exceptions.ThrowIfGuidEmpty(Guid parameter, String name)
   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Retrieve(String entityName, Guid id, ColumnSet columnSet, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>Expected non-empty Guid.</Message>
  <Timestamp>2012-05-03T16:44:39.8508813Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>
[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.RetrieveEntity]
[RetrieveEntity]
Entered ContactRelationshipDefinition.Execute(), Activity Instance Id: 149, Workflow Instance Id: 9d1eb654-1cf1-4e7b-b54f-0a523ab72dc1
ContactRelationshipDefinition.Execute(), Correlation Id: 00000000-0000-0000-0000-000000000000, Initiating User: 5efdf43e-0578-e111-a01e-00155d450361
Exiting ContactRelationshipDefinition.Execute(), Correlation Id: 00000000-0000-0000-0000-000000000000
</TraceText>
</OrganizationServiceFault>


Solution: Rather then not setting  EntityReference  out argument due to some condition, set it to null.
For example

protected override void Execute(CodeActivityContext context)
{
//outputParameterName is the outpurt parameter, if there are more then one the set all those to null as well.
     context.SetValue<EntitiyReference>(outPutParamenterName,null)

  //custom logic goes here
}