Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#69335 For Package @types/xrm : Changes for…
Browse files Browse the repository at this point in the history
… Postsave context by @pavansarma93
  • Loading branch information
pavansarma93 authored Apr 15, 2024
1 parent 15a43b1 commit 2c21286
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
40 changes: 39 additions & 1 deletion types/xrm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,31 @@ declare namespace Xrm {
disableAsyncTimeout(): void;
}

/**
* Interface for postsave event arguments
*/

interface PostSaveEventArguments{
/**
* Use this method to know information about a table being saved.
* It returns the table logical name, record ID, and table name if save was successful.
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getentityreference}
*/
getEntityReference():LookupValue;

/** Use this method to know whether the save operation was successful or failed.
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getissavesuccess}
*/
getIsSaveSuccess():boolean;

/**
* Use this method to know the error details on why save failed.
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getsaveerrorinfo}
*/
getSaveErrorInfo():object;

}

/**
* Interface for process stage change event arguments.
*/
Expand Down Expand Up @@ -911,6 +936,19 @@ declare namespace Xrm {
getEventArgs(): SaveEventArgumentsAsync;
}

/**
* Synchronous Form OnPostSave event context.
* In the API documentation, this is sometimes referred to as the executionContext.
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/save-event-arguments External Link: Form OnPostSave event}
* @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/execution-context External Link: Execution context (Client API reference)}
*/
interface PostSaveEventContext extends EventContext {
/**
* Gets postsave-event arguments.
*/
getEventArgs(): PostSaveEventArguments;
}

/**
* Interface for a process stage change event context
*/
Expand Down Expand Up @@ -959,7 +997,7 @@ declare namespace Xrm {
type SaveEventHandler = (context: SaveEventContext) => void;
type SaveEventHandlerAsync = (context: SaveEventContextAsync) => PromiseLike<void>;

type PostSaveEventHandler = (context: EventContext) => void;
type PostSaveEventHandler = (context: PostSaveEventContext) => void;

type ProcessStatusChangeHandler = (context: ProcessStatusChangedEventContext) => void;
type StageChangeEventHandler = (context: StageChangeEventContext) => void;
Expand Down
20 changes: 20 additions & 0 deletions types/xrm/xrm-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,3 +635,23 @@ const openFileSave = Xrm.Navigation.openFile({
}, {
openMode: XrmEnum.OpenFileOptions.Save,
});

// Demonstrate addOnPostSave/removeOnPostSave methods
const formContextDataEntityPostSaveMethods = (context: Xrm.Events.EventContext) => {
const formContext = context.getFormContext();
formContext.data.entity.addOnPostSave(contextHandler);
formContext.data.entity.removeOnPostSave(contextHandler);
};

//Demonstrate usage of Eventargs of postsave
function ActionOnPostsave(context:Xrm.Events.PostSaveEventContext){
const args = context.getEventArgs();

if(args.getIsSaveSuccess()){
//if success get id
let id = args.getEntityReference().id;
}else{
console.log(args.getSaveErrorInfo());
}

}

0 comments on commit 2c21286

Please sign in to comment.