Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
titleDataSource AfterSave Hook Sample
linenumberstrue
collapsetrue
/**
 * Event listener called on an after save changes on a dataSource/businessEntity,
 * used for updating the group title after a dataSource saveChanges operation
 * @param {akioma.swat.DataSource} dataSource Datasource object
 */
akioma.swat.GlobalEmitter.on( akioma.swat.GlobalHooks.DATASOURCE.AFTER_SAVE_CHANGES, async ( dataSource : akioma.swat.DataSource ) => {
  const containerControl = dataSource.container?.controller;
  const primaryDataSource = containerControl.dynObject?.getLink( "PRIMARYSDO:TARGET" );

  if ( containerControl?.view !== "window" || !primaryDataSource )
    return;

  const TaskbarObject = akioma.swat.MasterLayout.getBaseLayoutObject().getFirstChildByType( "grouptaskbar" ) as akioma.swat.Taskbar;

  const primaryDataSourceControl = primaryDataSource.controller;
  const SelfHdl = primaryDataSource.getValue( "selfhdl" );

  const res = await akioma.osiv.getRelatedPersonByUniqueKey( SelfHdl );
  const resArray = res.split( "|" );
  const parentId = resArray[ 0 ];
  const title = resArray[ 1 ];
  let groupData;
  if (parentId) {
    groupData = {
      id: parentId,
      title
    };
  } else {
    const shortTemplate = containerControl.opt.titleShort || containerControl.opt.TITLE;
    const titleShortTemplateCompiled = primaryDataSourceControl.getRecordDescription(shortTemplate);
    groupData = {
      id : TaskbarObject.getActiveGroupId(),
      title : titleShortTemplateCompiled
    };
  }
  TaskbarObject.updateGroup( groupData );
} );

...