Rollup field in Dynamics CRM 2016 - dynamics-crm-2016

Is there a way to force a rollup field to do it's calculation rather than having to "refresh" the field on the form?

You can use CalculateRollupFieldRequest in plugin when component field is updated:
CalculateRollupFieldRequest request= new CalculateRollupFieldRequest
{
Target = new EntityReference("<entityname>", recordId),
FieldName = "<rollup field to refresh>"
};
CalculateRollupFieldResponse response = (CalculateRollupFieldResponse)service.Execute(request);

Related

Can Dynamics Crm PartyList store an emailaddress

I have fields in activity form for email. It contains "to, cc and bcc" fields that are all fields of the type PartyList
The question is: Can I only store entity values like contact or account or can I also just store a email address which is not associated to any contact or account in the system?
Here is a picture explaining what I'm trying to achieve
As per this article it appears that the answer is yes via the addressUsed field.
Entity email = _sdk.Retrieve("email", emailId, new ColumnSet("to"));
EntityCollection to = email.GetAttributeValue<EntityCollection>("to");
if (to != null)
{
to.Entities.ToList().ForEach(party =>
{
EntityReference partyId = party.GetAttributeValue<EntityReference>("partyid");
bool isDeleted = party.GetAttributeValue<bool>("ispartydeleted");
string addressUsed = party.GetAttributeValue<string>("addressused");
// Do something...
});
}

Export emal template from CRM4 to CRM 2016

I need to export email templates from CRM 4 directly into CRM 2016. Can't go over the complete upgrade process so my best guess would be to export using services, connect to CRM 4 and then import into CRM 2016. The problem seems to be the import into CRM 2016 which throws a faultexception. But before I would start looking into to this I tried to recreate a template that I created in CRM 2016. Using the services but this also doesn't seem so easy to do..the process creates a copy of the email template but subject and body are missing. Does this need to be casted to something esle? What could be the problem here?
This is the code I used:
ColumnSet cols = new ColumnSet(new string[] { Template.AttributeLogicalNames.Title, Template.AttributeLogicalNames.Subject,
Template.AttributeLogicalNames.TemplateTypeCode, Template.AttributeLogicalNames.IsPersonal,
Template.AttributeLogicalNames.LanguageCode, Template.AttributeLogicalNames.Body });
QueryExpression query = new QueryExpression(Template.EntityLogicalName);
query.ColumnSet = cols;
query.Criteria = new FilterExpression();
query.Criteria.AddCondition("title", ConditionOperator.Equal, "TestTemplate Candidate");
EntityCollection results = _service.RetrieveMultiple(query);
foreach (var item in results.Entities)
{
Template template = new Template() { Title = ((Template)item).Title + "-2", Subject = ((Template)item).Subject,
TemplateTypeCode = ((Template)item).TemplateTypeCode, IsPersonal = ((Template)item).IsPersonal,
LanguageCode = ((Template)item).LanguageCode,Body = ((Template)item).Body
};
Guid templateid = _service.Create(template);
Console.WriteLine("Template created with Guid: {0}", templateid);
}
It seems I was missing some fields: subjectpresentationxml, presentationxml, generatetypecode

Need to calculate record Age and record Total Age field with the use of enhanced SLA in Microsoft dynamics CRM 2016

I have a requirement to calculate a record and record total age with the use of enhanced SLA. Is it possible?
Age : A record has a StartDate field and the value of StartDate is 1st March 2016 and there is another field named as EndDate and the value of EndDate is 31st March 2016, and the service getting hold for 3 days in this period, so the Age will be : 31 - 3 = 28
Total Age : Same as per above example but the difference is we does not need to include the hold days, So the Total Age will be : 31.
Thanks,
I found this interesting blog post by Aileen Gusni here
Intercept Column/Field Value in CRM View using RetrieveMultiple Plugin C#
Basically she creates a new field (in the example below it is pa_age), but she doesn't add it to the form or anything
Instead she catches the Retrieve and RetrieveMultiple messages in a Plugin and calculates this field as required.
I've pasted her code below
Note this is not my code, it was written by Aileen
public void Execute(IServiceProvider serviceProvider)
{
#region must to have
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
// Create service with context of current user
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
//create tracing service
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
#endregion
//this is to modify the Age column
if (context.OutputParameters.Contains("BusinessEntityCollection"))
{
var retrievedResult = (EntityCollection)context.OutputParameters["BusinessEntityCollection"];
foreach (Entity entity in retrievedResult.Entities)
{
if (entity.Contains("birthdate"))
{
var birthday = entity.GetAttributeValue<DateTime>("birthdate");
int age = CalculateAgeYear(birthday);
//modify the Age field
entity.Attributes["pa_age"] = age;
}
}
}
}
There are a few things to consider with this approach:
The pa_age field's value never gets set. It is added to the entity only so that it can be included in the view
this means that the pa_age field can't be included on the form or in reports because it will always be null
you can't use the pa_age field in advanced finds (filter), but of course you can add it to the advanced find results. The reason for this is the same as before: the value isn't actually saved in the database
Her blog post has much more information and screenshots of how it all works. I haven't tried this approach but it might be useful for you

selected Picklist value not saving in dynamic CRM?

I have added javascript for reverse the items in the picklist (rating) to the opportunity entity. It is done. but when I am filling the data and saving it, it is not saving the selected item from the rating picklist to the database. What do I have to do?
var oField = crmForm.all.opportunityratingcode;
var items = oField.options.length;
var arrTexts = new Array(items);
var arrValues = new Array(items);
for(i=0;i<items;i++)
{
arrTexts[i]=oField.Options[i].Text;
arrValues [i]=oField.Options[i].DataValue;
}
for(i=0;i<=items;i++)
{
oField.DeleteOption(i);
}
for(j=items;j>0;j--)
{
var oOption1 =oField.Options;
oOption1.Text=arrTexts[j-1];
oOption1.DataValue= arrValues [j-1];
oField.AddOption(oOption1.Text,oOption1.DataValue);
alert(oOption1.DataValue);
}
Sounds like you need to add a .ForceSubmit in the onSave of the form. This forces CRM to save attribute data changes that you have made with JavaScript.
e.g.
crmForm.all.attribName.ForceSubmit = true;
Check the CRM SDK here: http://technet.microsoft.com/en-us/library/cc189831.aspx

Find items is SSRS by Id

How do you find items in SSRS by ID? I tried to use the id returned by another find result, a new guid to string and small random string all of which return the same error:
The ID field has a value that is not valid. ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidElementException: The ID field has a value that is not valid.
Here is the code:
var request = new FindItemsRequest
{
Conditions = new[] { new SearchCondition { Name = "ID", Value = "test"} },
Folder = "/"
};
return _ssrsService
.FindItems(request)
.Items
I'm using SSRS 2005.
Pretty sure this can't be done through the SSRS service. Ended up finding all objects then using LINQ to filter down to the ID I need.
The MS documentation on the FindItems method says:
Applications that use FindItems typically accept user input for specific properties and property values. The searchable properties are Name, Description, CreatedBy, CreationDate, ModifiedBy, and ModifiedDate. The items that are returned are only those for which a user has Read Properties permission.

Resources