CRM 2011: change format of textfield to hyperlink

A customer asked me to change a single line text field to a hyperlink. As we know or as you have found out. It’s not possible to change the formatting of fields. Personally I think this is something which should be available. Maybe something for the next Dynamics CRM release?

Anyway, I had some options

1) Create a new field with hyperlink formatting, make sure the data is copied from the old field to the new, delete the old field  -> Too much work

2) Create a new field with hyperlink formatting, create a jscript that copies over the data –> Not too much work, but there has to be something else, right?

After some googling I found this URL: http://mscrmkb.blogspot.be/2012/01/convert-text-field-to-link-button-to.html (ALL the credits go to this person, this blogpost is more like a personal note).

This script will convert your field to a link button, how cool is that? Here is the script I used:

function ConvertToLink(fldName) {
    if(Xrm.Page.getAttribute(fldName).getValue()!=null)
    {
        var content = Xrm.Page.getAttribute(fldName).getValue();
        var btn = "<a href='javascript: void(0);' onclick=\"window.open(\'"+content+"',
        \'windowname1\', \'width=600, height=650\');  return false;\" style='color:blue;text-decoration:
        underline !important'>"+content+"</a>";
        var ctrl = Xrm.Page.ui.controls.get(fldName)._control;
        // Add the new button 
        ctrl.get_element().innerHTML += btn;
        // Hide the textbox 
        ctrl.get_element().firstChild.style.display = 'none';
    }
}

Creating a link to new document infoPath form in SharePoint 2010

If you want to create a hyperlink to the new document button of a forms library then you can use the following template.

http://{server}/_layouts/FormServer.aspx?xsnLocation=http://{fullpath to the library}/forms/template.xsn?DefaultItemOpen=1

Just change the server (incl. site collection) and the full path to the library.

That should do it!

Browsing SharePoint server from Word not possible

Quite puzzled today when I tried to save a file from Word to SharePoint. I got the message “You can’t open this location using this program. Please try a different location”. After googling a little bit I found a solution for my problem. This only seems to be happening when you try to open or save files to SharePoint from office application on a Windows Server OS. In my case the OS was Windows Server 2008 R2 so that checked out correctly.

To solve the problem you need to install the feature “Desktop Experience”.

- Go to Server Manager
- Click on “Features”
- Click on “Add Features”
- Select “Desktop Experience” and install additional required components if Windows asks you to

image

- Click “Next”
- Click “Install”
- Restart the server

Get optionset text from value or value from text

Here are two functions I use on a regular base when working with optionsets in CRM 2011 development projects. When you request an optionset attribute you will get an object of the type “OptionSetValue”. This object contains the value of the selected item. Sometimes this is enough but sometimes you want to retrieve the textual value behind this numeric value. Or sometimes you need to set a certain value in an optionset based on a value. If you then only have the text value, then you need a way to retrieve the numeric value behind that text value. For these common problems I have two methods:

/// <summary>
/// This function is used to retrieve the optionset value using the optionset text label
/// </summary>
/// <param name="service"></param>
/// <param name="entityName"></param>
/// <param name="attributeName"></param>
/// <param name="selectedLabel"></param>
/// <returns></returns>
private int GetOptionsSetValueForLabel(IOrganizationService service, string entityName, string attributeName, string selectedLabel)
{

    RetrieveAttributeRequest retrieveAttributeRequest = new
    RetrieveAttributeRequest
    {
        EntityLogicalName = entityName,
        LogicalName = attributeName,
        RetrieveAsIfPublished = true
    };
    // Execute the request.
    RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
    // Access the retrieved attribute.
    Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)
    retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.
    OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
    int selectedOptionValue = 0;
    foreach (OptionMetadata oMD in optionList)
    {
        if (oMD.Label.LocalizedLabels[0].Label.ToString().ToLower() == selectedLabel.ToLower())
        {
            selectedOptionValue = oMD.Value.Value;
            break;
        }
    }
    return selectedOptionValue;
}
/// <summary>
/// This function is used to retrieve the optionset labek using the optionset value
/// </summary>
/// <param name="service"></param>
/// <param name="entityName"></param>
/// <param name="attributeName"></param>
/// <param name="selectedValue"></param>
/// <returns></returns>
private string GetOptionsSetTextForValue(IOrganizationService service, string entityName, string attributeName, int selectedValue)
{

    RetrieveAttributeRequest retrieveAttributeRequest = new
    RetrieveAttributeRequest
    {
        EntityLogicalName = entityName,
        LogicalName = attributeName,
        RetrieveAsIfPublished = true
    };
    // Execute the request.
    RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest);
    // Access the retrieved attribute.
    Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)
    retrieveAttributeResponse.AttributeMetadata;// Get the current options list for the retrieved attribute.
    OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray();
    string selectedOptionLabel = null;
    foreach (OptionMetadata oMD in optionList)
    {
        if (oMD.Value == selectedValue)
        {
            selectedOptionLabel = oMD.Label.LocalizedLabels[0].Label.ToString();
            break;
        }
    }
    return selectedOptionLabel;
}

Iterating over requiredattendees in an appointment

In this sample code I will show you how to iterate over the requiredattandees attribute of an appointment. This  attribute is a list of activityparty records. An activityparty record can contain many different entity types, for example contacts and accounts:

proxy.EnableProxyTypes();
//If you want to iterate over every appointment use a RetrieveMumltipleRequest
var appointment = proxy.Retrieve(Appointment.EntityLogicalName,new Guid("FC8C427B-26AE-E111-ADAD-000C29CBD80B"),new ColumnSet(true));
List<ActivityParty> party = ((Appointment)appointment).RequiredAttendees.ToList<ActivityParty>();
foreach (ActivityParty ap in party)
{
    //You can retrieve metadata about a contact or an account by performing a new request
    if(ap.PartyId.LogicalName == Contact.EntityLogicalName)
        Console.WriteLine(string.Format("It's a contact with id {0}",ap.PartyId.Id));
    else if (ap.PartyId.LogicalName == Account.EntityLogicalName)
        Console.WriteLine(string.Format("It's an account with id {0}", ap.PartyId.Id));
}

General exception while creating an appointment in CRM 2011

Some time ago I had a serious problem when I tried to add the apppool user to CRM 2011. When I did that, not a single user could access CRM2011 anymore. I think, not sure, that it had something to do with the AD groups where the apppool user is a member of. I think that when I added that user to CRM2011 something changed and it messed up the windows permissions of that user. The trick was to delete every record manually from the CRM 2011 database where that user’s GUID was linked to. I know it’s not supported but it solved my problem.

Today I was trying to create an appointment and this resulted in a General Exception. Pretty weird but immediately I thought it had something to do with that same user from a couple of weeks ago because the GUID showed up in the errorlog:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Pointer record exists but referenced record of type 8 not found: aa60799f-49a3-e111-8444-000c29cbd80b

Scratching my head I was thinking: what can I do now? I thought I went through every table in CRM 2011 looking for that systemuserid.

I enabled tracing to see what exactly was going on. In the log I found the following query:

SELECT TOP 1000 [DisplayInServiceViews]
      ,[ObjectTypeCode]
      ,[BusinessUnitId]
      ,[CalendarId]
      ,[IsDisabled]
      ,[ResourceId]
      ,[VersionNumber]
      ,[OrganizationId]
      ,[Name]
      ,[SiteId]
  FROM [LRMDEPLOYMENT_MSCRM].[dbo].[ResourceBase]

This is the point where the error was returned. Now I knew that I missed a table. When an appointment is created CRM2011 probably tries to lookup all the available resources for scheduling. In this table there was still a reference to that “bad” userid and it resulted in an error. I removed this record and I could create my appointment.

CRM2011 keeps asking for user credentials

A great way to test security roles is to hold SHIFT and right click on Internet Exploter.

ScreenHunter_17 May. 29 09.44

This way you can run Internel Explorer in the context of different users in the domain. Today I was trying to that but CRM 2011 showing the prompt requesting username and password followed by a “Not Authorized” message. Pretty frustrating because I was sure I gave the correct security roles.

How to fix this problem?

- Go to Internet Options and click on the “Security” tab
- Click on the button “Custom Level” and scroll down until you reach the end of the list
- Under “User Authentication” select “Automatic logon with current user and password”

ScreenHunter_17 May. 29 09.40

How to modify report categories in CRM 2011

When you are creating a new report you have the possibility to categorize your report in report categories. By default you have

- Sales Reports
- Service Reports
- Marketing Reports
- Administrative Reports

Now I wanted to store a report under a custom report category. I hadn’t done this before so I started looking around in CRM 2011. Eventually I found the location where you could add/edit or change the order of report categories. To do this you need to go to “Settings –> Administration –> System Settings –> Reporting tab”

ScreenHunter_16 May. 25 08.27

Unknown error occurred while tracking email via CRM Outlook client

Seems that quite a lot of people have already experienced some kind of error with the CRM Outlook client. Today was one of those days again where I experienced an error. I did a clean install of the CRM 2011 Outlook client and connected to the CRM 2011 on premises environment. All seemed to be going extremely well. My contacts were being synchronized etc…

I wanted to track an email in CRM so I clicked the button “Track”. First a little pause and then boom, an error box popped up saying “An unknown error occurred while synchronizing data to Outlook.”.

ScreenHunter_09 Apr. 06 10.55

Ok not much to go with so I checked if there were any logs in the log directory: (“c:\Users\[USERNAME]\AppData\Local\Microsoft\MSCRM”)

No results there so I had to find a different solution to get some more information. I enabled tracing in Diagnostics tool that comes with the CRM 2011 Outlook client.

ScreenHunter_09 Apr. 06 12.56

Tried to track the email again to get that error box again and looked in the tracing file. (C:\Users\[USERNAME]\AppData\Local\Microsoft\MSCRM\Traces)

Now I did find something:

[2012-04-06 11:08:08.6] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrRetrieveAndSetRegardingIdInOutlook File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 999
>hr = 0×80004004
[2012-04-06 11:08:08.7] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrPromoteMailItemInCrm File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 1754
>hr = 0×80004004
[2012-04-06 11:08:08.7] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrCreateInCrm File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 1406
>hr = 0×80004004
[2012-04-06 11:08:08.7] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrCreateInCrm File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 1432
>hr = 0×80004004
[2012-04-06 11:08:08.94] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrCreateInCrm File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 1452
>hr = 0×80004004
[2012-04-06 11:08:08.94] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrCreateInCrm File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 1454
>hr = 0×80004004
[2012-04-06 11:08:08.95] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CMailItemHelper::HrPromoteItemToCrm File: c:\bt\32691\src\application\outlook\addin\emailhelper.cpp Line: 243
>hr = 0×80004004
[2012-04-06 11:08:08.95] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CItemHelper<struct Outlook::_MailItem>::PromoteItemToCrm File: c:\bt\32691\src\application\outlook\addin\ItemHelper.h Line: 354
>hr = 0×80004004
[2012-04-06 11:08:08.95] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CSyncToOutlook::SyncItemByTypeByAction File: c:\bt\32691\src\application\outlook\addin\synctooutlook.cpp Line: 1451
>hr = 0×80004004
[2012-04-06 11:08:08.96] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CSyncToOutlook::ProcessSyncResult File: c:\bt\32691\src\application\outlook\addin\synctooutlook.cpp Line: 1784
>hr = 0×80004004
[2012-04-06 11:08:08.97] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | CSyncToOutlook::ProcessSyncResult File: c:\bt\32691\src\application\outlook\addin\synctooutlook.cpp Line: 1831
>hr = 0×80004004
[2012-04-06 11:08:08.97] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | HrGetErrorDescription File: c:\bt\32691\src\application\outlook\addin\..\common\ResourceManagerEx.h Line: 148
>hr = 0×80004005
[2012-04-06 11:08:08.99] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | HrLoadManagedString File: c:\bt\32691\src\application\outlook\addin\..\common\ResourceManagerEx.h Line: 35
>hr = 0×80040203
[2012-04-06 11:08:08.99] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | LoadManagedString failed with hr = 0×80040203. Function: HrLoadManagedString File: c:\bt\32691\src\application\outlook\addin\..\common\ResourceManagerEx.h Line: 37
[2012-04-06 11:08:08.100] Process:OUTLOOK |Thread:5696 |Category: Unmanaged.Platform |User: PlatformUser |Level: Error | HrGetErrorDescription File: c:\bt\32691\src\application\outlook\addin\..\common\ResourceManagerEx.h Line: 154
>hr = 0×80040203

I’m just posing that long error message so that others with the same error will hopefully have something with this post.

So how did I fix this problem?

I though I was stuck because on the forums there wasn’t much information about this issue. Here’s what I did:

1) Go into control panel
2) Open Programs and Features
3) Select “Microsoft Dynamics CRM 2011 for Microsoft Outlook”
4) Click Uninstall/Change
5) Select Repair

ScreenHunter_09 Apr. 06 11.30

Hope this helps for you too!

Project setup for CRM 2011 custom workflow activity development

Today I wanted to create a custom workflow activity in code. I had some issues while creating and building this project in Visual Studio.By trial and error I slowly discovered what I was doing wrong. So here is you and for myself as future reference the setup of a CRM 2011 custom workflow activity.

1) Add XRM binaries from CRM 2011 SDK BIN folder. You need to add the following two:
- microsoft.xrm.sdk
- microsoft.xrm.sdk.workflow

2) These two assemblies have dependencies on System.ServiceModel and System.ServiceModel.Web so you need to add these too.
If you can’t add them, make sure that the target framework in you project properties is set to “.NET Framework 4″ and not “.NET Framework 4 Client Profile”

If you don’t add them then you’ll get build errors like:

- The referenced assembly “microsoft.xrm.sdk” could not be resolved because it has a dependency on “System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ which is not in the currently targeted framework “.NETFramework,Version=v4.0,Profile=Client”. Please remove references to assemblies not in the targeted framework or consider retargeting your project.
- The referenced assembly “microsoft.xrm.sdk.workflow” could not be resolved because it has a dependency on “System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ which is not in the currently targeted framework “.NETFramework,Version=v4.0,Profile=Client”. Please remove references to assemblies not in the targeted framework or consider retargeting your project.

3) Also add a reference to System.Runtime.Serialization if you are going to use an entities class generated by crmsvcutil.exe

Now you are finally set to start coding your custom CRM 2011 Workflow Activity Library…

4) Remove Activity1.xaml

3) Add a new C# class file to contain your custom workflow code

Once the workflow activity library is created…

5) Make sure to sign your assembly via the Project Properties / Signing tab

Custom workflow activity libraries need to be registered like a regular CRM plugin so…

6) Make sure you are a CRM 2011 deployment administrator otherwise you’ll not be able to register the plugin

Use the custom workflow activity in your CRM 2011 processes.

Volgende pagina »