Profile picture for user Volker Eckardt

We would like to set some model attributes depending on some other situations in the model. We already know that such a attribute set can be achieved by JavaScript. But we like to get this automated.

Event "Model will be saved" is raised

-> Java Script will be called

----> Java Script validates model situation

-------> Java Script updates attributes

The question now is: Can I raise a Java Script call right when I save a model? Is this possible?

Best Regards, Volker

by Stefan Geis
Posted on Wed, 03/24/2010 - 06:45

Volker,

AFAIK this can be done. Once you have the script ready, you configure it as described in this article; the most important points:

"You activate the macro by choosing “Available to users”.

To view or to change when the macro should be started automatically, select „Event” and „Select event…” in the “Context” property page of the macro."

hth

0
by Volker Eckardt Author
Posted on Fri, 04/02/2010 - 13:20

In reply to by André Vitor

Hello,

I am a little bit further, but still I stuck. The macro runs and works until it reaches the bold line. Here it says that the function AssignedModels does not exist in oObject.

What I am trying to achieve is to identify if a certain model type is attached to the function object just updated. In reports the function AssignedModels works, but not in the macro.

What alternative function can i use instead?

 

That's my macro code, that shows me via MsgBox the just updated function name as expected (Event = Assignment Created):

var oChangedObjects = getChangedObjects();

for (var i = 0; i < oChangedObjects.length; i++) {

// Get Object Reference and Name

var oObject = oChangedObjects[i];

var oObjectName = Designer.getAttribute(oObject, Constants.AT_NAME, null);

// until here it works

Dialogs.MsgBox(oObjectName);

// this line errors out

var lo_models = oObject.AssignedModels(Constants.MT_VAL_ADD_CHN_DGM);


 

// this will work too: Designer.setAttributePersistent(oObject, Constants.AT_NAME, "New Name", null);



}

function getChangedObjects() {

var oChangedObjects = new Array();

var oSelectedObjects = Context.getSelectedObjects();



for (var i = 0; i < oSelectedObjects.length; i++) {

var oObject = oSelectedObjects[i];

// this does not work either, why?:  if (Designer.isModified(oObject, true)) {

oChangedObjects.push(oObject);

// }

}

return oChangedObjects;

}

Thanks a lot in advance!

Volker

0
by Ralf Scheidhauer
Posted on Sun, 04/04/2010 - 17:29

Hi Volker,

the equivalent for AssignedModels(...) in the macro API is called Designer.getAssignedModels(...). The latter does not allow direct filtering for certain model types, so you have to call getType() on the result yourself and compare it with the desired model type.

Designer.isModified(...) can only be called on models (it returns true if the model M itself or some of the occurences and definitions reachable from M have been modified); currently there is no way to find out whether a certain object has been modified or which items will be saved by the current save operation.

Ralf



 

0
by Volker Eckardt Author
Posted on Mon, 04/05/2010 - 23:30

Hi,

Thanks a lot for your help. My code is now complete and during my first tests it works exactly as I like it to work. But now with some more test cases there is an issue with the events and I don't know if this is solveable at all.

I am keeping track of changes in attached models, so I am using the event "Assignment created". This fires when I create a new assignment. What I now need in addition is the Event "Assignment removed". But in fact such an event does not exist. There are two more called "Assignment is to be created/deleted (vetoable)", but these are to my understanding fireing in advance to a change, therefore I can not identify what model type will be changed or what models are left (attached).

If I can not identify this "removal" event, my whole solution will not work, and I would need to go away from macros.

Any idea what else I could do to get these two different "Assignment" events?

Thanks, Volker

 

 

0
by Ralf Scheidhauer
Posted on Tue, 04/06/2010 - 16:27

Hi again,

in deed an event "Assignment removed" is missing, so we'll check whether we can add it for a future version.

But in principle you can also solve your problem by listening for "Assignment is to be deleted (vetoable)" (if you rely on that no one does a veto): you can get the model that is going to be assigned via "Context.getSelectedModels()" and the object to which the assignment is being done via "Context.getSelectedObjects()".

 

Ralf

 

0
by Volker Eckardt Author
Posted on Tue, 04/06/2010 - 18:52

Hi Ralf,

thanks a lot for your continious support. It would be excellent if I could bring it to work. Unfortunately this "Assignment is to be deleted (vetoable)" event fires first, and afterwards the assignment gets deleted. So if I look into the current list of assigned models, always I am getting more back than after the deletion.

This way I can not get the "left" or "removed" models. I played already with the "Context.getSelectedModels()", but this variable returns only values if I deal with the model and not in my case, where I deal with one single object only.

I was also trying to get the model object hierarchy out of "Context.getSelectedModels()" . In case this variable is filled the other one related to Objects is empty. So what I would need to do is coming from SelectedModels and look to find the Objects and finally there attached models. As I havent seen any example I would really appreciate if I could get some more details what I would need to do.

My code is not long (ax. 25 lines), so if it would be helpful to get it I could share it here.

Thanks a lot

Volker

0
by Ralf Scheidhauer
Posted on Wed, 04/07/2010 - 08:51

Hi Volker,

I did my proposal just by having a quick look at our code, i.e. which information is packed into the event, but did not write a macro. Now I tried to experiment with some macro code. but unfortunately there seems to be something broken in my local installation, so the macro reacting on "Assignment is to be deleted (vetoable)" does not even start.

But form your posting I assume, that the macro listening on the above event does start in your case? If so, then you can try to get access to the model to whcih the assignment refers as follows:

    var args = Context.getProperty(Constants.EVENT_ARGUMENTS);
    var modelToWhichAssignmentToBeDeletedRefers= args.getValue(Constants.EVENT_ARGUMENT_MODEL)

If this does not work, then you can try something else (which is quite ugly, but should do the job :-) )

    var obj = Context.getSelectedObjects()[0]
    var assignmentsBefore = Designer.getAssignedModels(obj);
    
    // basically execution will now continue and later on when the deletion
    // of the assignment is done the code below will be executed
    
    var job = { run: function () {
        var assignmentsAfter = Designer.getAssignedModels(obj);
        Context.MsgBox("before: " + assignmentsBefore.length + ", after: " + assignmentsAfter.length)
    } }
    var runnable = new java.lang.Runnable(job);
    Packages.javax.swing.SwingUtilities.invokeLater(runnable);

 

Ralf

 

0
by Volker Eckardt Author
Posted on Fri, 04/23/2010 - 13:37

In reply to by sstein

Hi Ralf,

thanks a lot for your replay, took some time to bring it to work. But now it is running like a charm. I used mainly the first code set:

    var args = Context.getProperty(Constants.EVENT_ARGUMENTS);

    var modelToWhichAssignmentToBeDeletedRefers= args.getValue(Constants.EVENT_ARGUMENT_MODEL)

I will post this solution in some days, but like to add some more comments first.

Best Regards, Volker

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock