How to detect lifecycle event "ARTIFACT_OPENED" or "ARTIFACT_CLOSED" refers to a module?
One answer
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);
}
}
});
});
// 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);
}
}
});
});