Posts

Showing posts with the label Dynamics CRM 2011

Session state not storing or saving gotcha

Hi folks, Recently in my SP-CRM project I noticed that my session state that I enabled in SharePoint doesn't use SQL Server for storage (it uses inproc). Although it works fine so far, but the recommended way is to enable sessionstateservice using Enable-spsessionstateservice powershell cmdlet. So I did this, and my application was broken. After debugging, I realized it could not store my object into the session table in the database. I read up documentation and the requirement for storing object is that the object must be serializable . I checked my class and it already had serializable attribute. However, there is a property with the type of the generated class created by crmsvcutil and I had a feeling this was the culprit, and I was right! The solution is to not use any of the crmsvcutil generated class in your session variables, otherwise you wouldn't be able to save it.  HTH, Andreas

CRM 2011 - set or assign record owner

Hi, Just a recap of how to set the record owner or assign a new owner through the sdk. When creating a record, you don't need to use AssignRequest. Simply set the OwnerId and call SaveChanges of your context. But if the record already exists, then you must use AssignRequest to assign the record to the new owner. HTH, Andreas

CRM 2011 - Add many to many relationship + checking if relationship exists between entities (N:N)

Hi all, Using service context AddLink, you can create N:N relationship in CRM. However you still need to check if the relationship has already been created between the two entities, otherwise you would get 'Insert duplicate key' error. Thanks to this blog  I don't have to create helper functions to check the existing relationship. Rather than using AddLink method that is tied to a service context, I just use the normal Associate method of the IOrganisationService: HTH, Andreas

CRM 2011 SharePoint 2013 integration ADFS setup for Single Sign On (SSO)

Hi All, After several hours trying to make this work with the help from technet articles, forums and the help from my colleagues, I managed to get this working. My configuration: 1. CRM 2011 has been configured as IFD using ADFS  (see here ) 2. My original site is in Default zone (can be either http/https) with Windows Auth 3. I configured ADFS + map LDAP attributes 4. Web application is extended to other zone (in my case Intranet) to be the ADFS site The reason we can't have 1 site for both Default and ADFS is because the CRM List component does not like the Sign In page when hitting 'Documents' section inside CRM. The reason we want Windows Auth as well is to be able to crawl the site as well as for admin purposes. -------------------------------------------------------------------------------------------------------------------- SETTING UP ADFS: Go to your ADFS Server, open your ADFS management: 1. Add relying Party Trusts with this configuration • En...

Sharepoint 2013 CRM2011 Document Upload and Document Location Helper (CSOM and OM)

Hi all, Playing around with SharePoint CRM 2011 integration, I managed to construct a helper function that would be useful for future projects. This is when you want to upload document to SharePoint as well as creating document location in CRM 2011. There are several ways of uploading documents to SharePoint. 1. Object Model 2. Client Object Model 3. Rest API In this post, I will show you the first two. If your code is sitting in SP server, you can use the traditional object model. Here you go: You might want to impersonate credentials when uploading to a different SP site. With Firefox, when I try to upload to secured SP site (https) I got prompted login box which is annoying (as opposed to single sign on with IE/Chrome). So as a workaround we can use the Client Object Model way to upload to SharePoint in order to specify the credentials: Here I also ensure that the folder exists before we upload document (otherwise create them!). Lastly, the CRM 2011 documen...

CRM 2011 Linq Retrieve Many to Many N:N Records

Hiya, As you all know, you can use Query Expressions or FetchXML to retrieve N:N records. Good news, we can also use LINQ if you wish to. Let's say we have a portal account (for website login) that has N:N to organisation and we want to grab all portal accounts for a given organisation (in my case I have early bound entities): Easy? :) HTH, Andreas

CRM 2011 Early Bound Entities Serialization / Deserialization

Hi all, Just want to tell my experience regarding this topic - maybe it will save your time. Crmsvcutil gives you generated entities file which can be a time saver. This is all good until you want to use those entities on client side (in my case I want to bring them to my knockout JS functionality combined with AJAX and web services to provide better user experience) Serialization = works fine (when I retrieve the records). The trick is to use JSON .NET  , and with the help of Partial class you can extend the generated entity class from crmsvcutil. To get all properties serialized you need to use the [JsonObject(MemberSerialization.OptOut)] attribute on that partial class as well. Deserialization  = The problem appears when you try to deserialize (when I try to save the records). The AttributeCollection class becomes the culprit in this, complaining that it Cannot create and populate list type of AttributeCollection . Looking at the JSON Stringify ajax data that ge...

CRM 2011 Kerberos Troubleshooting - Report Wizard FetchXml Related Issue

Hi all, Recently one of our clients had issue when running reports created through the report wizard. After some investigations, it turned out that the FetchXMLDataSource is having some connection issue with an error log recorded something like:  A call to SSPI failed, see inner exception. This is surely a kerberos authentication issue. After a few good hours reading documentations on how to set up proper kerberos for CRM 2011, I managed to get all working nicely. I summarised all what I've done so that it may help you down the track: Check the CRMAppPool service account whether you are using NetworkService or a domain account. The best practice is to use custom domain account (separate from your CRM admin account as well). In my case I have something like domain\CRM2011APP. If you set this up during installation it should at least be in the PrivUserGroup and PrivSqlServerGroup as well. Open your AD manager and check if that account has kerberos delegation enabled (On de...

CRM 2011 LINQ Left Join Through Entity Reference

Let's say we have a custom lookup field new_accountid on our phonecall activity (don't ask me why I don't just use from/to field :)) and that field is NOT a required field. We want to get the account number using LINQ in our code somehow. This is the way to do it. The trick is that we have to check whether the new_accountid is null and combine those records with the ones that are null. Hope this helps, Andreas

CRM 2011 Get OptionSetValue Value through Label

Sometimes we want to be able to get the OptionSetValue value from the label itself. One way is to use the metadata request and loop through it but this is a cumbersome way. The easier way is to put those OptionSetValue data into an enum like this: We use Description Attribute for the Label so that it supports string format. Then we use this helper method: And there you go. You can easily get the value like this: Hope this helps, Andreas

CRM 2011 Activity Party Add, Remove, Delete from code

Sometimes we want to append the activity party list, update particular item in the existing activity party list, or remove specific activity party from the list. Below is what I discovered on how to do this. Since we can't use the Create/Update/Delete method from the service context on ActivityParty entity, we need to alter the content of the list before attaching to the Activity Field. In my case I have an ActivityRecipient custom entity that have N:1 to Email entity. Whenever the user add/update/delete this custom entity, the corresponding 'To' recipients gets updated as well. I use this function in my pre create/update/delete message of my ActivityRecipient entity. Note: for some reason Recurring Appointment doesn't like Organization Service Context (early bound), therefore we have to use IOrganizationService with Retrieve Request. Hope this helps, Andreas

CRM 2011 SMS custom activity Characters Remaining field

Paul Nieuwelaar in his blog has implemented some javascript for the characters remaining field. This saves me a lot of time from reinventing the wheel. All I then did was to set the default value to the field (160 characters for SMS). Also make sure that you put the 160 limit on the multiline textbox, but leave the minimum value for the charactersremaining field to be -20000000 to avoid the annoying message box. Hope this helps, Andreas

CRM 2011 disable lookup type for customer field or partylist

Sometimes we want to lock the lookup type for customer field type or partylist type. To do this, use the javascript (e.g. Account Type only): Hope this helps, Andreas

CRM 2011 Export Entities Tabs and Sections Name

CRM does not provide a functionality to list all your tab and section names. With the help of SQL XML parsing feature, I managed to create an sql script to read the FormXML of the entities and parse out the tabs and sections name. This is useful if you want to see all the tabs and sections that you have added. Enough said, this is the script: Hope this helps, Andreas

CRM 2011 Ajax Loading Message Screen with JQuery

Image
When you use ajax request in CRM2011 (for example, the OData call), the user is not notified when this process happens in the background. Although this call is relatively fast, sometimes you can't predict the performance of it and you want some kind of notification that lets the user know what's happening. Fortunately with the power of JQuery you can easily make this happen. In my case, I have a custom 'Create Opportunity' button on my custom entity form that gets the data from that entity (and related entity) and create opportunity with those data. When creating the opportunity using the OData way, I will show the loading message popup with the animated OOTB CRM progress gif image. To make this happen, it's simple. Just put this function into your onLoad form: You notice the center() method above. This is an add-on to the jQuery method that you can safely put on your jQuery file: That's it. Now whenever there is an Ajax call on the form, you will...

CRM 2011 JQuery OData REST Endpoints Create Record

In CRM 2011, we can create record easily using JQuery and OData. This will get triggered asynchronously using the ajax functionality. Create Record function from the SDK: To create new record, you just need to instantiate your object and call the function. The tricky part is when you want to assign Lookup field or OptionSetValue. You can get more info on this from the SDK itself. Here is an example:

CRM 2011 Javascript Fetch XML synchronous or asynchronous call

Using helper function to execute FetchXML request is great. The code below is retrieved from this blog , and all I had to do is to add extra logic when parsing the XML result because I want to grab the attributes from the related entity as well. Modified FetchUtil.js: To use it you just need to do it like this (synchronous) If it's asynchronous the last bit will be: The parsed result object can be queried like this: Hope this helps, Andreas

CRM 2011 Import Custom Workflow Error - Assembly must be registered in isolation

This error does not tell much, but I fixed it by adding myself as a Deployment Administrator. Hope this helps, Andreas

CRM 2011 Partial Refresh with jQuery

This post is a little update on my previous post regarding the Form Refresh after Sub-grid changes. I find the previous solution annoying in the way that when the user click 'Save' or 'Save and New' , the parent form that got refreshed would get the focus. Also, if the sub-grid had paging on it, the form would get refreshed when you move to the next page - thus you will always get the first page of the sub-grid. In order to avoid this I found a way to do a partial form element refresh using jQuery load function. The only tricky part is that you have to move your subgrid out of the tab that you want to do partial refresh on. (i.e. partial refresh does not work on sub-grid element). In my case, my fields that I want to update is on General Tab: hope this helps, Andreas

CRM 2011 Custom Workflow Activity - Send Email to Managers

In CRM 2011 (not online), you can create custom workflow activity for things that are not achievable using the OOTB workflow. In my scenario, I want to send Overdue Case Reminder to group of users (in this case - managers) when a case has reached the Follow Up By date. If you look at the SystemUser, it has a manager field by default. However, I need to be able to send the email to multiple managers. My idea is that we create a separate Security Role (e.g. Managers) and put all managers in that role. Then we create a custom workflow activity to get all the users in that role and construct an email to notify them when the case is overdue. Note: for the CaseLink input, I'm using the CRM 2011 Workflow Utilities to generate the Case Link and put it into the Email Description field. Hope this helps, Andreas