context.on

In the context of an entity view (Code tab > After Generate JS subtab), attaches a handler to an event.

Syntax

Copy
context.on(eventName: "goToRecord", handler: (e: IViewGoToRecordEvent) => void): IDisposable

 

Parameter Description
eventName The name of the event. There are two events available: gotoRecord and goToInsert, described below.

handler

Thefunction that is executed when the event is triggered.

goToRecord

Syntax

Copy
context.on("goToRecord", function(e){});

The handler's parameter, context, is an object of type IViewGoToRecordEvent.

Copy
interface IViewGoToRecordEvent{
        cancel: boolean;
        rowData: any;
        options: IViewGoToRecordEventOptions;
}
interface IViewGoToRecordEventOptions{
        formName: string;
        recordId: string;
        entityName: String;
 }

If you want to prevent navigation to the record, set e.cancelto true.

Copy
context.on("goToRecord", function(e){
        if(!condition){
        e.cancel = true;
        ebs.showMessage("You cannot go to the details of this row", "info");
        }
});

If you want to change the default navigation to the record, change e.options.

Copy
context.on("goToRecord", function(e){
        var status = e.rowData["a_status"];
        if(status == "special"){
        e.options.formName = "specialForm";
        }
 });

goToInsert

Syntax

Copy
context.on("goToInsert", function(e){});

The handler's parameter, context, is an object of type IInsertRecordOptions:

Copy
interface IInsertRecordOptions{
        cancel: boolean;
        options: IViewGoToInsertEventOptions;
}
interface IViewGoToInsertEventOptions{
        formName?: string;
        entityName?: string;
        defaultVals?: string;
}

If you want to prevent navigation to the insert page, set e.cancel to true.

Copy
context.on("goToInsert", function(e){
    if(!condition){
        e.cancel = true;
        ebs.showMessage("You cannot insert into this entity", "info");
    }
 });

To change the default navigation to the insert page, change e.options.

Copy
context.on("goToInsert", function(e){
        e.options.formName = "specialForm";
 });

Response

IDisposable