Skip to content

Instantly share code, notes, and snippets.

@TeaDrivenDev
Created March 5, 2022 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeaDrivenDev/ee4e70e8a2cbdbfa570fcfcfcfc5c71f to your computer and use it in GitHub Desktop.
Save TeaDrivenDev/ee4e70e8a2cbdbfa570fcfcfcfc5c71f to your computer and use it in GitHub Desktop.
A simple plugin for Dynamics CRM 2011 in F#
namespace FSharp
open System
open Microsoft.Xrm.Sdk
type TestPlugin() =
interface IPlugin with
member this.Execute serviceProvider =
let organizationServiceFactory = serviceProvider.GetService(typeof<IOrganizationServiceFactory>) :?> IOrganizationServiceFactory
let organizationService = organizationServiceFactory.CreateOrganizationService(System.Nullable())
let context = serviceProvider.GetService(typeof<IPluginExecutionContext>) :?> IPluginExecutionContext
let account = context.PreEntityImages.["Image"]
let name = account.GetAttributeValue<string> "name"
let oldName = string name //if String.IsNullOrWhiteSpace(name) then "" else name
let record = new Entity("account", Id = context.PrimaryEntityId)
record.["name"] <- oldName + " Fsharped"
organizationService.Update record
@heliconho
Copy link

Hi. Thanks for the demo! i've been trying to figure out how to set parameter to the plugin but no luck. by any chance you have a same for it?

Much Appreciated.
Helicon

@TeaDrivenDev
Copy link
Author

@heliconho Unfortunately not. I left my MSCRM job shortly after I starting to learn F#, so I never did much with it beyond trying to get a simple plugin to work.

@heliconho
Copy link

@heliconho Unfortunately not. I left my MSCRM job shortly after I starting to learn F#, so I never did much with it beyond trying to get a simple plugin to work.

don't worry about it! its good to know you got away from MSCRM. i think i will just stick to C# for these development task haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment