How to Trigger code in DNG.
![](http://jazz.net/_images/myphoto/8286c1b01a1a0345677347177fd7bc28.jpg)
Accepted answer
![](http://jazz.net/_images/myphoto/8286c1b01a1a0345677347177fd7bc28.jpg)
You can use the Javascript API to execute some javascript code as soon as one of the available events is triggered (ARTIFACT_SELECTED, ARTIFACT_OPENED, ARTIFACT_SAVED, ARTIFACT_CLOSED).
To use this API, you have to gain access to the Javascript RM Object - which first of all is available only in widgets.
Maybe there are also possibilities to access this object from outside widgets (e.g. in javascript code which you included using a Theme).
If you only use a widget, the user must first add it to the sidebar in order to activate your functionality.
You can find the Javascript API Documentation here:
In this topic:
I posted a short code example which executes some javascript as soon as a module is opened:
RM.Event.subscribe(RM.Event.ARTIFACT_OPENED, function(openedArtifact){
RM.Data.getAttributes(openedArtifact, [RM.Data.Attributes.FORMAT], function(result){
if(result.code != RM.OperationResult.OPERATION_OK)
console.error("Could not retrieve attributes of opened artifact!");
else if(result.data[0].values[RM.Data.Attributes.FORMAT] == RM.Data.Formats.MODULE)
console.debug("Module opened!"); }); });
Following this schema, this could be adapted in a way to be executed as soon as an artifact is saved.
You can then either implement your desired business logic directly in Javascript, or trigger some other code e.g. in a Server Application.
One other answer
![](http://jazz.net/_images/myphoto/8286c1b01a1a0345677347177fd7bc28.jpg)
As far as I know you can not extend DNG to be able to do that, unfortunately.
Comments
![](http://jazz.net/_images/myphoto/31126fdf6be66cf20190d6af5f232cb9.jpg)
Correct, you cannot extend or configure the web UI or server side code to do that.
What kind of functionality do have in mind?
![](http://jazz.net/_images/myphoto/bf99256d9bc89c3e4ec3688d8ff0f9e4.jpg)
Maybe I do not understand the question correctly, but what if you use a widget with some javascript which is executed when the ARTIFACT_SAVED lifecycle event is triggered (see section »Lifecycle events« in https://jazz.net/wiki/bin/view/Main/RMExtensionsAPI602 )?
You cannot prevent saving this way (because the event is triggered after the save operation), but I read the question like if some other functionality in addition to the save is demanded.
![](http://jazz.net/_images/myphoto/8286c1b01a1a0345677347177fd7bc28.jpg)
Yes Philipp,
I want to add additional functionality on save.
Comments
Philipp Waldinger
Feb 24 '17, 11:51 a.m.Do you want to execute some functionality in addition to or instead of the save?