Automatically reload page in sidebar

Hello,

I need the record registry on the sidebar page to automatically refresh when the page is opened. I'm trying to use crt.HandleSidebarOpenRequest (version 8.1.4). Here is my code:
 

   handlers: /**SCHEMA_HANDLERS*/[
   {
   request: "crt.HandleSidebarOpenRequest",
   handler: async (request, next) => {
   console.log("Обробник викликано");
   const result = await next?.handle(request);
   console.log("Після next.handle(request)");
   const handlerChain = sdk.HandlerChainService.instance;
   // Оновлюємо дані при відкритті сторінки
 
   await handlerChain.process({
       type: "crt.LoadDataRequest",
       $context: request.$context,
       params: {
           config: {
               loadType: "reload",
               useLastLoadParameters: true
           },
           dataSourceName: "DataGrid_69bg53fDS"
       }
   });
   console.log("вуцауца");
   return result;
}
   }

         

       ]/**SCHEMA_HANDLERS*/,

 

However, the handler is not triggering. Could you please help?

Like 0

Like

1 comments

Hello,

A developer can subscribe to sidebar open/close events in a remote module.

To subscribe to the open or close sidebar events in your code, follow these steps:

1. Create an Angular class in the project. To do this, run the ng g class my-sidebar-open.handler command at the command line terminal. Files of the MySidebarOpenHandler class will be added to the src/app/ project directory.

2. Implement the handler.

a. Open the my-sidebar-open.handler.ts file.

b.Define the class of request that inherits base type and contains sidebarCode property.

c. Inherit the BaseRequestHandler class with the new type (2.b.) from the @creatio-devkit/common library.

d. Specify the type of the handler.

e. Specify the type of the request as crt.HandleSidebarOpenRequest.

f. Implement the handle method with some custom logic.

    i. Since this handler will handle HandleSidebarOpenRequest requests from all sidebars, you should check the code of the sidebar before performing any custom actions.

    ii. Write your custom logic.

    iii. Call this.next?.handle(request) in order to process all other handlers of this request.

g. Save the file.

import { BaseRequestHandler } from "@creatio-devkit/common";
class SidebarEventRequest extends BaseRequest {
	public readonly sidebarCode!: string;
}
@CrtRequestHandler({
	type: `usr.MySidebarOpenHandler`,
	requestType: 'crt.HandleSidebarOpenRequest',
})
export class MySidebarOpenHandler extends BaseRequestHandler<SidebarEventRequest> {
	public async handle(request: SidebarEventRequest): Promise<void> {
		if (request.sidebarCode === 'UsrMyCustomSidebar') {
			//WRITE YOUR OWN LOGIC HERE
		}        
		await this.next?.handle(request);
	}
}

3. Build the project. To do this, run the npm run build command at the command line terminal.

Show all comments