Skip to content

Instantly share code, notes, and snippets.

View pawelgradecki's full-sized avatar

pawelgradecki

View GitHub Profile
@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;
var crmClient = new CrmServiceClient(ConfigurationManager.ConnectionStrings["D365"].ConnectionString);
if (crmClient.IsReady)
{
using (var ctx = new OrganizationServiceContext(crmClient))
{
var result = ctx.CreateQuery<Contact>()
.Where(a => a.FirstName == "Jan")
.Select(a => new Contact
{
public class ServiceResponse
{
public string RecognitionStatus { get; set; }
public int Offset { get; set; }
public int Duration { get; set; }
public Nbest[] NBest { get; set; }
}
public class Nbest
{
public class ConvertSpeechToTextPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
var organizationServiceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var orgService = organizationServiceFactory.CreateOrganizationService(null);
tracingService.Trace("Plugin started");
function openEntityForm() {
var entityFormOptions = {
entityName: "account",
useQuickCreateForm: false
};
var formParameters = {
name: "Sample Account",
description: "This is example of how you can prepopulate the fields on opened entity"
};
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
namespace Validation.Plugin.CoreLib
function showAlertDialog() {
var localizedResult = Xrm.Utility.getResourceString("odx_/resx/messages", "qualifyingLeadMessage");
var alertStrings = {
confirmButtonLabel: "OK",
text: localizedResult
};
var alertOptions = {
height: 200,
width: 400
function openWebResource() {
var windowOptions = {
openInNewWindow: false,
height: 400,
width: 400
};
Xrm.Navigation.openWebResource("new_mywebresource.html", windowOptions, "someAdditionalParameter");
}
function openUrl() {
var url = "http://google.com";
var openUrlOptions = {
height: 400,
width: 800
};
Xrm.Navigation.openUrl(url, openUrlOptions);
}
function openFile() {
var file = {
fileContent: "bXkgc2VjcmV0IGNvbnRlbnQ=", //Contents of the file.
fileName: "example.txt", //Name of the file.
fileSize: 24, //Size of the file in KB.
mimeType: "text/plain" //MIME type of the file.
}
Xrm.Navigation.openFile(file, 2);
}