Bug in DNG Script API 5.0 while getting ARTIFACT_TYPE attribute?
Hello, I received a strange result while querying for ARTIFACT_TYPE attribute from the artifact reference achieved from the getContentAttributes() API. Consider the below code:
RM.Event.subscribe(RM.Event.ARTIFACT_SELECTED, displayAttrs); function displayAttrs(artRefs) { if (artRefs.length > 0) { console.log("reading attrs values...\n"); var artRef1 = artRefs[0]; RM.Data.getAttributes(artRef1, [RM.Data.Attributes.FORMAT, RM.Data.Attributes.IDENTIFIER], function(opResult1) { if (opResult1.code === RM.OperationResult.OPERATION_OK) { console.log("op ok"); if (opResult1.data[0].values[RM.Data.Attributes.FORMAT] === RM.Data.Formats.MODULE) { console.log("module"); console.log(opResult1.data[0].values[RM.Data.Attributes.IDENTIFIER]); RM.Data.getContentsAttributes(artRef1, [RM.Data.Attributes.IDENTIFIER], function(opResult2) // (1) //RM.Data.getContentsAttributes(artRef1, [RM.Data.Attributes.ARTIFACT_TYPE], function(opResult2) // (2) { if (opResult2.code === RM.OperationResult.OPERATION_OK) { console.log(opResult2.data.length); // (A) opResult2.data.forEach(function(item) { RM.Data.getAttributes(item.ref, RM.Data.Attributes.IDENTIFIER, function(opResult3) // (3) //RM.Data.getAttributes(item.ref, RM.Data.Attributes.ARTIFACT_TYPE, function(opResult3) // (4) { if (opResult3.code === RM.OperationResult.OPERATION_OK) { console.log(opResult3.data.length); // (B) console.log(opResult3); console.log(opResult3.data); console.log(opResult3.data[0]); console.log(opResult3.data[0].values); console.log(opResult3.data[0].values[RM.Data.Attributes.IDENTIFIER]); // (5) //console.log(opResult3.data[0].values[RM.Data.Attributes.ARTIFACT_TYPE]); // (6) } else { console.log("oh no"); } }); }); } }); } else { console.log("not module"); } } else { console.log("op error"); } }); } } If I use (1) --> output of (A) is 4 (my module has 4 items) If I use (2) --> output of (A) is 1 --> what happened? If I use (1) + (3) + (5) --> output of (B) is (for individual item): 1 Object { code: "OK", data: Array[1] } Array [ Object ] Object { ref: Object, values: Object } Object { http://purl.org/dc/terms/identifier: 15 } 15 If I use (1) + (4) + (6) --> output of (B) is: 1 Object { code: "OK", data: Array[1], warning: Object } Array [ Object ] Object { } undefined --> The different b/w the 2 outputs is the present of the "warning" object. I try to print it also & get the following result: "Object { message: "The following ArtifacRefs were not available to perform your specified action on, and may have been deleted", data: Array[1] }" Why the ArtifactRef is available to query other attributes rather than ARTIFACT_TYPE? I would like to perform some actions on the artifacts of specific type in my module. Any advice for this case? Thank you. |
Accepted answer
I cannot reproduce the same issue with your code in RDNG 5.0.2, and I can see the expected correct result even with (2)+(4)+(6). But I cannot find any related defects fixed in 5.0.1 and 5.0.2, assuming there is indeed a defect in RDNG 5.0. So I'm not quite sure whether the issue has been (indirectly) fixed somehow. If you are still seeing the same issue in your environment, I suggest you just add "IDENTIFIER" along with "ARTIFACT_TYPE" when calling getAttributes() and getContentsAttributes() to make sure that "ArtifactRef" is returned as part of the result.
Tuan Nguyen Minh selected this answer as the correct answer
Comments
Tuan Nguyen Minh
commented May 05 '15, 8:13 a.m.
Hi, thanks for the answer. Even I cannot reproduce the issue today, the same code just works like a charm. I didn't make any change from yesterday when I encountered the issue, I really don't understand. Yesterday I did exactly what you've just suggested by add the "IDENTIFIER" along with "ARTIFACT_TYPE", but whenever the "ARTIFACT_TYPE" is presented, the result array always has only 1 element, if I remove it, it returned 4. It has just driven me in mad...
|
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.