Skip to content

Instantly share code, notes, and snippets.

View pawelgradecki's full-sized avatar

pawelgradecki

View GitHub Profile
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DemoCodeNoProxy")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[EntityLogicalName("account")]
public class MyAccount : Entity
{
public MyAccount() : base("account") { }
public string odx_clientcode
{
get
{
return this.GetAttributeValue<string>("odx_clientcode");
[EntityLogicalName("account")]
public class MyAccount : Entity
{
public MyAccount() : base("account") { }
[AttributeLogicalName("odx_clientcode")]
public string odx_clientcode
{
get
{
public class MyEntity : Entity
{
public MyEntity(string entityName) : base(entityName) { }
protected string GetAttributeName(string propertyName)
{
return "odx_" + propertyName.ToLowerInvariant();
}
protected T GetAttribute<T>([CallerMemberName]string propertyName = null)
[EntityLogicalName("account")]
public class MyAccount : MyEntity
{
public MyAccount() : base("account") { }
[AttributeLogicalName("odx_clientcode")]
public string ClientCode
{
get => GetAttribute<string>();
set => SetAttribute(value);
public class MyEntity : Entity
{
protected string GetAttributeName(string propertyName)
{
return this.GetType().GetProperties().FirstOrDefault(p => p.Name == propertyName).GetCustomAttribute<AttributeLogicalNameAttribute>().LogicalName;
}
protected T GetAttribute<T>([CallerMemberName]string propertyName = null)
{
return this.GetAttributeValue<T>(GetAttributeName(propertyName));
@pawelgradecki
pawelgradecki / TransactionPlugin.cs
Created June 18, 2017 20:03
Transaction Plugin
public class TransactionPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = factory.CreateOrganizationService(null);
var counter = GetCounter(service);
counter["new_name"] = "lockme";
function changeCompositeFieldLabel(attributeName, label) {
var attribute = Xrm.Page.getAttribute(attributeName);
if (attribute != null) {
attribute.controls.forEach(function (c) {
c.setLabel(label);
});
}
}
//Usage
@pawelgradecki
pawelgradecki / SolutionExportFixer.cs
Last active October 3, 2017 13:44
Removes attributes that do not exist in the system anymore, from the solution
static void Main(string[] args)
{
var solutionUniqueName = "SOLUTIONNAME";
var orgService = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
var solutionComponentQuery = new QueryExpression("solutioncomponent");
solutionComponentQuery.Distinct = true;
solutionComponentQuery.ColumnSet.AddColumns("objectid", "componenttype", "solutioncomponentid");
var solutioncomponentSolutionLink = solutionComponentQuery.AddLink("solution", "solutionid", "solutionid");
solutioncomponentSolutionLink.EntityAlias = "aa";
solutioncomponentSolutionLink.LinkCriteria.AddCondition("uniquename", ConditionOperator.Equal, solutionUniqueName);
@pawelgradecki
pawelgradecki / createActivityAttachment.js
Created July 19, 2017 14:57
How to create an attachment using WebApi in Dynamics 365
var activityId = "059C0532-906C-E711-9409-00155D018D00";
var activityType = "appointment"; //or any other entity type
var entity = {};
entity["objectid_activitypointer@odata.bind"] = "/activitypointers(" + activityId + ")";
entity.body = "ZGZnZA=="; //your file encoded with Base64
entity.filename = "test";
entity.subject = "test";
entity.objecttypecode = activityType;