It's all about the answers!

Ask a question

How to Trigger code in DNG.


Jayshri Burde (2818) | asked Feb 24 '17, 5:40 a.m.

Hi,

 
When we edit module in DNG it is automatically saves after focus lost. If I want to execute other functionality on save then is it possible to do that? If yes, how can I do that.  Any help would greatly appreciated. 


Comments
Philipp Waldinger commented Feb 24 '17, 11:49 a.m. | edited Feb 24 '17, 11:51 a.m.

Do you want to execute some functionality in addition to or instead of the save? 

Do you want your code to be executed in any case (so the user cannot disable it, e.g. to enforce some policies), or is it ok if the user can enable and disable it (e.g. for some convenience functionalities)? 

Accepted answer


permanent link
Philipp Waldinger (1313) | answered Feb 27 '17, 10:40 a.m.

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.

Jayshri Burde selected this answer as the correct answer

One other answer



permanent link
Ralph Schoon (63.6k33646) | answered Feb 24 '17, 6:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As far as I know you can not extend DNG to be able to do that, unfortunately. 


Comments
Bas Bekker commented Feb 24 '17, 9:39 a.m.
JAZZ DEVELOPER

Correct, you cannot extend or configure the web UI or server side code to do that.
What kind of functionality do have in mind?


Philipp Waldinger commented Feb 24 '17, 11:45 a.m. | edited Feb 24 '17, 11:51 a.m.

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.


Jayshri Burde commented Feb 27 '17, 5:01 a.m.

 Yes Philipp,

I want to add additional functionality on save.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.