Today I start to create a tool to help me with some ordinary activity in the upgrade process to CRM2016. I needed a way to migrate DCP entity in the Mail Merge Template. The first problem that I found, is the possibility to enable “Note” in the entity and the second problem was to insert the Note Area inside the main form. The check of the property inside the entity is not enough because we need to edit manually the form. The ckeck enabled the Note Button in edit Form:


I wanted an automatic process. After scounting I found this solution:
Enable and Insert Note Code
private void EnableMailMergeTemplateAnnotation(IOrganizationService service)
{
//Check if note area exists in the entity
if (CheckNoteExist(service))
{
Log.Info("Enable Note - the note panes exists in the form ...");
}
else
{
//Get Entity Metadata for the entity mailmergetemplate
RetrieveEntityRequest retrieveBankAccountEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = "mailmergetemplate"
};
RetrieveEntityResponse retrieveMailMergeTemplateMetaData = (RetrieveEntityResponse)service.Execute(retrieveBankAccountEntityRequest);
EntityMetadata mailMergeTemplate = retrieveMailMergeTemplateMetaData.EntityMetadata;
// Enable Notes
UpdateEntityRequest enableNoteRequest = new UpdateEntityRequest
{
Entity = mailMergeTemplate,
HasNotes = true
};
service.Execute(enableNoteRequest);
//Update Form
UpdateEntityForm("mailmergetemplate", service);
//Publish Update
PublishAllXmlRequest publishRequest = new PublishAllXmlRequest();
service.Execute(publishRequest);
}
}
Add Note Area in the form
public void UpdateEntityForm(String entityLogicalName, IOrganizationService service)
{
QueryExpression q = new QueryExpression("systemform");
q.ColumnSet = new ColumnSet("formxml");
q.Criteria.AddCondition(new ConditionExpression("type", ConditionOperator.Equal, 2));
q.Criteria.AddCondition(new ConditionExpression("objecttypecode", ConditionOperator.Equal, "mailmergetemplate"));
var entities = service.RetrieveMultiple(q);
if (entities != null)
{
string mainForm = entities.Entities.First().Attributes["formxml"].ToString();
// Definition of a custom tab containing the custom attributes created in this sample
String noteRow = @"<row/>
<row/>
<row>
<cell id=""{33537195-ad98-07d8-7267-2e93e712905d}"" showlabel=""true"" rowspan=""15"" auto=""false"" colspan=""2"">
<labels>
<label description=""Note Text"" languagecode=""1033"" />
</labels>
<control id=""notescontrol"" classid=""{06375649-c143-495e-a496-c962e5b4488e}"" />
</cell>
</row>
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
<row />
</rows>
</section>
<section name=""Categorization""";
if (mainForm.Contains("notescontrol"))
{
Log.Info("Note exists in the form...");
}
else
{
string newForm = mainForm.Replace("</rows></section>
<section name=\"Categorization\"", noteRow);
//Updateing the entity form definition
entities.Entities.First().Attributes["formxml"] = newForm;
//saving the bank account form
service.Update(entities.Entities.First());
}
}
}
And with this code my life is more easy.
"Mi piace":
"Mi piace" Caricamento...