serving the solutions day and night


Saturday, May 17, 2014

MS Dynamics CRM - Change Grid view background color

My client wants to change the grid view color based on the contact entity address type value is "Ship To". So i added a button in the contact entity "<ribbondiffxml>", but i didn't make it display, you can see there is no command in the "<displayrules>". I added new <customrule> to call the javascript("dns_contact") function ("BackGroundColorGrid") to change the color. Make sure you added jquery in your webresources.

Same way you can change color for the grid.

Tuesday, May 13, 2014

MS Dynamics CRM - Attach SSRS Report in Email Attachments

This blog will explain to call SSRS report, convert SSRS report content to HTML and place it in the body of the email, same SSRS report will convert to PDF and attached to the email.

It contains 2 class, one is email and call EmailAttachment() function to generate email. Second class name is ReportServerCredentials, it extends IReportServerCredentials, code at the end of blog.

using System.ServiceModel.Description;
using System.Security.Principal;
using System.Net;
using Microsoft.Reporting.WebForms;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Client;

MS Dyanmics CRM - Add Notes Attachment in Email

//See the previous blog about how to create new email
GUID emailID = CreateEmail(toUsers, ccUsers, subject, body);
//Pass contactID
Guid contactID = new Guid(paramValue);

private AddNotesAttachmentinEmail(GUID emailID, GUID contactID)
    using (XrmServiceContext xsContext = new XrmServiceContext(CRMServiceProxy))
        var qry = from anno in xsContext.AnnotationSet
              where anno.contact_Annotations.contactid == contactID
              && anno.IsDocument == true
              && anno.MimeType != null
              select new

        foreach (var rec in qry)
        ActivityMimeAttachment ama = new ActivityMimeAttachment();
        ama.Subject = rec.Subject;
        ama.ObjectId = new EntityReference("email", emailID);
        ama.ObjectTypeCode = "email";
        ama.FileName = rec.FileName;
        ama.Body = rec.DocumentBody;
        ama.MimeType = rec.MimeType;

MS Dynamics CRM - Create Email

List<ActivityParty> ccUsers = CCUsers(string ccEmails);
List<ActivityParty> toUsers = DNSTeamUsers();

CreateEmail(toUsers, ccUsers, subject, body);

//Create Email address, email will be in Draft format.

private Guid CreateEmail(List<ActivityParty> toUsers, List<ActivityParty> ccUsers, string subject, string body)
    Guid orgid, userid;
    SystemUserEntity.WhoAmIResponse(out orgid, out userid);

    ActivityParty fromUser = new ActivityParty
    PartyId = new EntityReference(SystemUser.EntityLogicalName, userid)

    Email email = new Email();
    email.From = new ActivityParty[] { fromUser };
    if (toUsers!=null)
    email.To = toUsers.ToArray();
    if (ccUsers!=null)
    email.Bcc = ccUsers.ToArray();
    email.Subject = subject;

    email.Description = body;

    //Assign regarding    
    email.RegardingObjectId = new EntityReference(contact.EntityLogicalName, contactid);
    //connect OrganizationServiceProxy
    Guid emailGUID = CRMServiceProxy.Create(email);
    return emailGUID;