1- import { MnComponent , OnInit } from "@primno/core" ;
1+ import { MnComponent , PageType , MnOnFormLoad , MnOnFieldChange , FormEventArg } from "@primno/core" ;
22
3+ /**
4+ * The AppComponent class is defined as a component by the @MnComponent decorator.
5+ * A component is a class that contains an individual piece of functionality to apply to a form or a grid.
6+ * This sample component will show a notification when the form is loaded and when the name field is changed.
7+ */
38@MnComponent ( {
9+ /**
10+ * The scope define when the component will be loaded.
11+ * In this case, the component will be loaded on forms of the account entity.
12+ */
413 scope : {
5- pageType : "entityrecord"
14+ pageType : PageType . record ,
15+ entityName : "account"
616 }
717} )
8- export class AppComponent implements OnInit {
9- public mnOnInit ( ) : void {
10- Xrm . Navigation . openAlertDialog ( { text : "Welcome from Primno" } ) ;
18+ export class AppComponent {
19+ /**
20+ * onFormLoad is an event handler that will be called when the form is loaded due to the @MnOnFormLoad decorator.
21+ * Show the notification "Welcome from Primno".
22+ */
23+ @MnOnFormLoad ( )
24+ public onFormLoad ( eventArg : FormEventArg ) {
25+ eventArg . formCtx . ui . setFormNotification ( "Welcome from Primno" , "INFO" , "welcome" ) ;
26+ }
27+
28+ /**
29+ * onNameChange is an event handler that will be called when the name field is changed due to the @MnOnFieldChange decorator.
30+ * Show the notification "Name changed to <name>".
31+ */
32+ @MnOnFieldChange ( "name" )
33+ public onNameChange ( eventArg : FormEventArg ) {
34+ const name = eventArg . formCtx . getAttribute ( "name" ) . getValue ( ) ;
35+ eventArg . formCtx . ui . setFormNotification ( `Name changed to ${ name } ` , "INFO" , "nameChanged" ) ;
1136 }
1237}
0 commit comments