It's all about the answers!

Ask a question

How to detect lifecycle event "ARTIFACT_OPENED" or "ARTIFACT_CLOSED" refers to a module?


Adrian Haw (2991242) | asked Mar 28 '16, 5:52 a.m.
The documentation is not very clear - does the event ARTIFACT_OPENED or ARTIFACT_CLOSED event relate to a module only or is there a way to detect the type of opened/closed artifact? Reason is the called function should only be executed when a user opens or closes a module.

One answer



permanent link
Adrian Haw (2991242) | answered Mar 28 '16, 10:04 a.m.
OK, looking at some other example code from IBM I think it can be solved by the following.

// Subscribe to the ARTIFACT_OPENED event
RM.Event.subscribe(RM.Event.ARTIFACT_OPENED, function(ref) {
    // Get the artifact attributes
    RM.Data.getAttributes(ref, RM.Data.Attributes.FORMAT, function(opResult) {
        // Check previous call completed OK
        if (opResult.code === RM.OperationResult.OPERATION_OK) {
            // Load an array with the attributes of the artifact
            var attrs = opResult.data[0];
            // If the artifact is a module (the value of the attribute 'format' of the artifact is identical to that of a module)
            if (attrs.values[RM.Data.Attributes.FORMAT] === RM.Data.Formats.MODULE) {
                // call a function to do something with the module having handle 'ref'
                processModule(ref);
            } else {
                // it's not a module so do something else (or do  nothing) with the artifact
                doSomethingElse(ref);
            }
        }
    });
});

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.