Skip to content

Instantly share code, notes, and snippets.

@gashupl
gashupl / XrmDefinitelyTyped.exe.config
Created September 26, 2017 07:19
XrmDefinitelyTyped.exe.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="url" value="https://INSTANCE.crm4.dynamics.com/XRMServices/2011/Organization.svc" />
<add key="username" value="[email protected]" />
<add key="password" value="pass@word1" />
<add key="out" value="../TypeScripts/XRM" />
<add key="solutions" value="" />
<add key="entities" value="account, contact, opportunity" />
<add key="jsLib" value="../foo_/scripts/common" />
@gashupl
gashupl / tsconfig.json
Created September 26, 2017 07:21
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"outDir": "../foo_/scripts",
"sourceMap": true,
"removeComments": true,
"sourceRoot": "/"
}
}
@gashupl
gashupl / DataServices.ts
Created September 26, 2017 07:23
DataServices.ts
/// <reference path="Common.ts" />
/// <reference path="../Xrm/Form/account/Main/Account.d.ts" />
/// <reference path="../Xrm/Form/opportunity/Main/Opportunity.d.ts" />
/// <reference path="../Xrm/Web/opportunity.d.ts" />
module Foo.Dyn365.DataServices {
export interface IOpportunityDataService {
getAccountOpportunities(accountId, onSuccess): void
}
@gashupl
gashupl / Common.ts
Created September 26, 2017 07:24
Common.ts
/// <reference path="../Xrm/Form/account/Main/Information.d.ts" />
module Foo.Dyn365.Common {
declare var Xrm;
export class Form {
constructor() {
}
@gashupl
gashupl / Account.ts
Last active September 19, 2025 17:56
Account.ts
/// <reference path="../XRM/Form/account/Main/Information.d.ts" />
/// <reference path="../common/DataServices.ts" />
module Foo.Dyn365.Account {
export class EventHandlers {
static onLoad(): void {
console.log("onLoad invoked from Account");
let dataService = new Foo.Dyn365.DataServices.OpportunityDataService();
let form = new Form(dataService);
public class SubjectsRepository : DocumentDbRepositoryBase, IDocDbSubjectsRepository
{
readonly IMongoCollection<Subject> dataCollection;
public SubjectsRepository(IMongoDatabase documentDb) : base(documentDb)
{
this.dataCollection = documentDb.GetCollection<Subject>("Subject");
}
public List<Subject> GetAll()
{
{
"_id" : LUUID("4d6c1fce-d035-11e7-a82a-000d3a2a3caf"),
"LogicalName" : "subject",
"Attributes" : [
{
"k" : "modifiedby",
"v" : {
"_t" : "EntityReference",
"_id" : LUUID("45bf6873-9e6a-ac4e-af72-dda713ccf2a5"),
"LogicalName" : "systemuser",
public void RunImport()
{
List<Subject> subjects = this.unitOfWork.SubjectsRepository.GetAll(); //Getting data from the document db
ImportSubjects(subjects, null); //Import data to Dynamics 365 instance
}
public void ImportSubjects(List<Subject> subjects, Guid? parentSubject)
{
var subjectsToBeImported = subjects.Where<Subject>(s => s.ParentSubject?.Id == parentSubject).ToList<Subject>();
subjectsToBeImported.ForEach(s =>
public static Guid ToGuid(int value)
{
byte[] bytes = new byte[16];
BitConverter.GetBytes(value).CopyTo(bytes, 0);
return new Guid(bytes);
}
public class ItemsController : ODataController
{
private readonly IItemsRepository itemsRepository;</code>
public ItemsController(IItemsRepository itemsRepository)
{
this.itemsRepository = itemsRepository;
}
[EnableQuery]