Merge pull request #4059 from 6ix4our/master

Added Xrm.Page API v6, 7.0, and 7.1 (Microsoft Dynamics CRM)
This commit is contained in:
Masahiro Wakame
2015-04-12 08:39:21 +09:00
8 changed files with 7408 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
// Type definitions for Microsoft Dynamics xRM ClientGlobalContext.js.aspx
// Project: http://msdn.microsoft.com/en-us/library/gg328255.aspx
// Definitions by: David Berry <https://github.com/6ix4our/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="xrm.d.ts" />
/**
* Gets the xRM application context, for HTML web resources
* @returns {Xrm.Context} The application context for the user's current session.
* @remarks The ClientGlobalContext.js.aspx page will include some global event handlers. These event handlers will
* cancel the onselectstart, contextmenu, and ondragstart events.
*/
declare function GetGlobalContext(): Xrm.Context;
+143
View File
@@ -0,0 +1,143 @@
// Type definitions for Microsoft Parature extentions to Xrm.Page - available for CRM Online Only
// Project: http://msdn.microsoft.com/en-us/library/gg328255.aspx
// Definitions by: David Berry <https://github.com/6ix4our/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="xrm.d.ts" />
declare module Xrm.Page
{
/**
* Interface for Parature's knowledge base search control.
*
* @sa Control
*/
export interface KbSearchControl extends Control
{
/**
* Use this method to add an event handler to the OnResultOpened event.
*
* @param {Function} handler The handler.
*/
addOnResultOpened( handler: () => void ): void;
/**
* Use this method to add an event handler to the OnSelection event.
*
* @param {Function} handler The handler.
*/
addOnSelection( handler: () => void ): void;
/**
* Use this method to get the text used as the search criteria for the knowledge base management control.
*
* @return The search query.
*/
getSearchQuery(): string;
/**
* Use this method to get the currently selected result of the search control. The currently selected result also
* represents the result that is currently open.
*
* @return The selected result.
*/
getSelectedResult(): KbSearchResult;
/**
* Use this method to remove an event handler from the OnResultOpened event.
*
* @param {Function} handler The handler.
*/
removeOnResultOpened( handler: () => void ): void;
/**
* Use this method to remove an event handler from the OnSelection event.
*
* @param {Function} handler The handler.
*/
removeOnSelection( handler: () => void ): void;
/**
* Use this method to set the text used as the search criteria for the knowledge base management control.
*
* @param {string} query The text for the search query.
*/
setSearchQuery( query: string ): void;
}
/**
* Interface for a Parature knowledge base search result.
*/
export interface KbSearchResult
{
/**
* The HTML markup containing the content of the article.
*/
answer: string;
/**
* The Article ID in a Parature department
*/
articleId: string;
/**
* Unique Article ID for the Parature system.
*/
articleUid: string;
/**
* The date the article was created.
*/
createdOn: Date;
/**
* The date the article was or will be expired.
*/
expiredDate: Date;
/**
* Whether the article is associated with the parent record or not
*/
isAssociated: boolean;
/**
* Date on which the article was last modified.
*/
lastModifiedOn: Date;
/**
* Support Portal URL of the article.
*/
publicUrl: string;
/**
* Whether the Article is in published or draft state.
*/
published: boolean;
/**
* The title of the article.
*/
question: string;
/**
* The rating of the article.
*/
rating: number;
/**
* A short snippet of article content which contains the areas where the search query was hit.
*/
searchBlurb: string;
/**
* Link to the article in the Parature service desk.
*/
serviceDeskUri: string;
/**
* The number of times an article is viewed on the Parature portal by customers.
*/
timesViewed: number;
}
}
+2071
View File
File diff suppressed because it is too large Load Diff
+69
View File
@@ -0,0 +1,69 @@
/// <reference path="xrm-6.d.ts" />
/// <reference path="clientglobalcontext.d.ts" />
function _getContext()
{
var errorMessage = "Context is not available.";
if ( typeof GetGlobalContext != "undefined" )
{ return GetGlobalContext(); }
else
{
if ( typeof Xrm != "undefined" )
{
return Xrm.Page.context;
}
else { throw new Error( errorMessage ); }
}
}
var crmContext = _getContext();
var grids = Xrm.Page.getControl(( control ) =>
{
return control.getControlType() === "subgrid";
});
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
{
gridControl.refresh();
});
var lookupAttribute = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
lookupAttribute.addCustomFilter( `<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
</filter>`, "account" );
lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
var lookupValues = lookupAttribute.getAttribute().getValue();
if ( lookupValues !== null )
if ( !lookupValues[0].id || !lookupValues[0].entityType )
throw new Error("Invalid value in Lookup control.");
Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); });
Xrm.Page.ui.tabs.forEach(( tab ) =>
{
tab.setVisible( true );
tab.sections.forEach(( section ) =>
{
section.setVisible( true );
});
});
Xrm.Page.data.entity.addOnSave(( context ) =>
{
var eventArgs = context.getEventArgs();
if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose )
eventArgs.preventDefault();
});
alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` );
alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` );
+2350
View File
File diff suppressed because it is too large Load Diff
+72
View File
@@ -0,0 +1,72 @@
/// <reference path="xrm-7.0.d.ts" />
/// <reference path="clientglobalcontext.d.ts" />
function _getContext()
{
var errorMessage = "Context is not available.";
if ( typeof GetGlobalContext != "undefined" )
{ return GetGlobalContext(); }
else
{
if ( typeof Xrm != "undefined" )
{
return Xrm.Page.context;
}
else { throw new Error( errorMessage ); }
}
}
var crmContext = _getContext();
var grids = Xrm.Page.getControl(( control ) =>
{
return control.getControlType() === "subgrid";
});
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
{
gridControl.refresh();
});
var lookupAttribute = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
lookupAttribute.addCustomFilter( `<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
</filter>`, "account" );
lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
var lookupValues = lookupAttribute.getAttribute().getValue();
if ( lookupValues !== null )
if ( !lookupValues[0].id || !lookupValues[0].entityType )
throw new Error("Invalid value in Lookup control.");
if (Xrm.Page.data.process != null)
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) });
Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); });
Xrm.Page.ui.tabs.forEach(( tab ) =>
{
tab.setVisible( true );
tab.sections.forEach(( section ) =>
{
section.setVisible( true );
});
});
Xrm.Page.data.entity.addOnSave(( context ) =>
{
var eventArgs = context.getEventArgs();
if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose )
eventArgs.preventDefault();
});
alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` );
alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` );
+103
View File
@@ -0,0 +1,103 @@
/// <reference path="xrm.d.ts" />
/// <reference path="clientglobalcontext.d.ts" />
/// <reference path="parature.d.ts" />
/// Demonstrate clientglobalcontext.d.ts
function _getContext()
{
var errorMessage = "Context is not available.";
if ( typeof GetGlobalContext != "undefined" )
{ return GetGlobalContext(); }
else
{
if ( typeof Xrm != "undefined" )
{
return Xrm.Page.context;
}
else { throw new Error( errorMessage ); }
}
}
var crmContext = _getContext();
/// Demonstrate iterator typing
var grids = Xrm.Page.getControl(( control ) =>
{
return control.getControlType() === "subgrid";
});
var selectedGridReferences: Xrm.Page.LookupValue[] = [];
/// Demonstrate iterator typing with v7.1 additions
grids.forEach(( gridControl: Xrm.Page.GridControl ) =>
{
gridControl.getGrid().getSelectedRows().forEach(( row ) =>
{
selectedGridReferences.push( row.getData().getEntity().getEntityReference() );
})
});
/// Demonstrate generic overload vs typecast
var lookupAttribute = <Xrm.Page.LookupControl>Xrm.Page.getControl( "customerid" );
var lookupAttribute2 = Xrm.Page.getControl<Xrm.Page.LookupControl>( "customerid" );
/// Demonstrate ES6 String literal syntax
lookupAttribute.addCustomFilter( `<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
</filter>`, "account" );
lookupAttribute.addPreSearch(() => { alert( "A search was performed." ); });
/// Demonstrate strong-typed attribute association with strong-typed control
var lookupValues = lookupAttribute.getAttribute().getValue();
if ( lookupValues !== null )
if ( !lookupValues[0].id || !lookupValues[0].entityType )
throw new Error("Invalid value in Lookup control.");
/// Demonstrate v7.0 BPF API
if (Xrm.Page.data.process != null)
Xrm.Page.data.process.moveNext(( status ) => { alert( `Process moved forward with status: ${status}` ) });
/// Demonstrate v7.1 Quick Create form
Xrm.Utility.openQuickCreate(( newRecord ) => { alert( `Newly created record Id: ${newRecord.id}` ); }, "account" );
/// Make all controls visible.
Xrm.Page.ui.controls.forEach(( control ) => { control.setVisible( true ); });
/// Make all tabs and sections visible.
Xrm.Page.ui.tabs.forEach(( tab ) =>
{
tab.setVisible( true );
tab.sections.forEach(( section ) =>
{
section.setVisible( true );
});
});
/// Demonstrate OnSave event context.
Xrm.Page.data.entity.addOnSave(( context ) =>
{
var eventArgs = context.getEventArgs();
if ( eventArgs.getSaveMode() === Xrm.Page.SaveMode.AutoSave || eventArgs.getSaveMode() === Xrm.Page.SaveMode.SaveAndClose )
eventArgs.preventDefault();
});
/// Demonstrate ES6 String literal with templates
alert( `The current form type is: ${Xrm.Page.ui.getFormType() }` );
alert( `The current entity type is: ${Xrm.Page.data.entity.getEntityName() }` );
+2586
View File
File diff suppressed because it is too large Load Diff