Execute script on save button

Hello community,

     I'm interested if there is possibility to run a script when we create new dataset in database.

     When we create and save dataset to run the script?

Labels (1)
0 Kudos
1 Reply
hoebbel
Crownpeak employee
Crownpeak employee

Re: Execute script on save button

Hello Bojan,

take a look at the ID... at. This can be used to listen for corresponding changes and then react to them accordingly.

Here is an example script that I used for testing:

import de.espirit.firstspirit.agency.IDProviderEventAgent;

import de.espirit.firstspirit.event.RevisionEvent;

import de.espirit.firstspirit.event.EventInfo;

import java.util.function.Consumer;

import java.util.function.Predicate;

eventFilter = new Predicate<EventInfo>() {

   boolean test(info) {

      context.logInfo("EVENTAGENT-Info Objekt: " + info);

      return true;

   }

};

eventListener = new Consumer<RevisionEvent>() {

   void accept(event) {

      context.logInfo("EVENTAGENT-Event received for Revision" + event.getRevision());

      context.logInfo("EVENTAGENT-Project check: " + event.getUserService().getProject().getLanguages());

      changes = event.getChanges();

      context.logInfo("EVENTAGENT-Event.getChanges:" + changes);

      it = changes.iterator();

      while (it.hasNext()) {

         change = it.next();

         changeInfo = change.getEventInfo();

         element = change.getElement();

         context.logInfo("EVENTAGENT-Event.change - INFO:" + changeInfo );

         context.logInfo("EVENTAGENT - displayname" + element.getDisplayName(context.project.masterLanguage));

      }  

   }

};

eventAgent = context.requireSpecialist(IDProviderEventAgent.TYPE);

context.logInfo("EVENTAGENT-eventAgent" + eventAgent);

eventAgent.addListener(eventFilter,eventListener);

Thread.sleep(10000*60*1);

eventAgent.removeListener(eventListener);

For test purposes this script was run as a script action within a schedule entry. But for your use case, you should create a module with an appropriate service.

best regards

Holger

0 Kudos