Getting the artifact's related module's attributes
Hello everyone,
I am trying to create a simple widget which when you select an artifact, it will find the module the artifact is in and displays the modules name, description and identity attributes for quick reference. However, I am struggling to get it to work correctly, when the following line executes RM.Data.getAttributes(selectedArtifact, [RM.Data.Attributes.CONTAINING_MODULE], function(attrResult) attrResult.data[0].values is an object which I try to pass into another getAttributes function to get the attributes of the module I get fail code error. What am I doing wrong? Note: I am using Doors Next Gen 5.0.1 Below is the xml file to add the sample widget <?xml version='1.0' encoding='UTF-8' ?> <!-- Licensed Materials - Property of IBM attr-links-ext.xml © Copyright IBM Corporation 2015 U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. --> <Module specificationVersion='2.0'> <ModulePrefs title='Module Attributes' height='500' scrolling='true'> <Require feature='com.ibm.rdm.rm.api'/> </ModulePrefs> <Content type='html'> <![CDATA[ <html> <head> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script> <script> $(function() { RM.Event.subscribe(RM.Event.ARTIFACT_SELECTED, function(selected) { if (selected.length == 1) { selectedArtifact = selected[0]; RM.Data.getAttributes(selectedArtifact, [RM.Data.Attributes.CONTAINING_MODULE], function(attrResult) { if (attrResult.code != RM.OperationResult.OPERATION_OK) { alert('get containing module failed in getContainingModule'); return; } else { var module = attrResult.data[0].values; RM.Data.getAttributes(module, function(result) { if (result.code != RM.OperationResult.OPERATION_OK) { alert('get attributes of module failed in getContainingModule'); return; } var moduleAttributes = result.data[0]; $('#descript').val(moduleAttributes.values[RM.Data.Attributes.DESCRIPTION]); $('#identity').val(moduleAttributes.values[RM.Data.Attributes.IDENTIFIER]); $('#moduleName').val(moduleAttributes.values[RM.Data.Attributes.NAME]); }); } }); } else { $('#descript').val(''); $('#identity').val(''); $('#moduleName').val(''); } }); }); </script> <link rel='stylesheet' type='text/css' href='rpe_formatting/css/attr-links-ext.css'> </head> <body> <table id='menutable'> <1tr> <1td colspan='2' class='noborder'> <1h3 class='sliderheading'>Name</h3> <1/td> <1/tr> <1tr> <1td class='blankcell'> <1/td> <1td> <1textarea rows='4' cols='20' id='moduleName'></textarea> <br/> <1/td> <1/tr> <1tr> <1td colspan='2' class='noborder'> <1h3 class='sliderheading'>Identifier</h3> <1/td> <1/tr> <1tr> <1td class='blankcell'> <1/td> <1td> <1textarea rows='1' cols='20' id='identity'></textarea> <br/> <1/td> <1/tr> <1tr> <1td colspan='2' class='noborder'> <1h3 class='sliderheading'>Description</h3> <1/td> <1/tr> <1tr> <1td class='blankcell'> <1/td> <1td> <1textarea rows='4' cols='20' id='descript'></textarea> <br/> <1/td> <1/tr> </table> </body> </html> ]]> </Content> </Module> Ignore the 1's in the table, it was just to stop the table causing issues on the page |
One answer
Change your code from
var module = attrResult.data[0].values;to var module = attrResult.data[0].values[RM.Data.Attributes.CONTAINING_MODULE];and see if it works for you. Currently this attribute only works on a "module artifact", not on a "base artifact", and I believe it is working as designed. Surely it works differently from the way the "where used" section of an artifact does. In the API specification, the explanation of this attribute is "the Used In property of an artifact that refers to a containing module" - I believe the singular form of "a containing module" is intentional. In other words, this attribute only returns one module and it only makes sense when the artifact is a "module artifact". Comments
Andrew Lloyd
commented Jan 22 '15, 6:34 p.m.
Hi Donald,
Donald Nong
commented Jan 22 '15, 6:52 p.m.
Hi Andrew,
|
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.