Skip to main content

Execute script on save button

Comments

1 comment

  • Zendesk API User
    Author: hoebbel - 7/2/2021 6:56

    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

Please sign in to leave a comment.