It's all about the answers!

Ask a question

Getting the artifact's related module's attributes


Andrew Lloyd (5346) | asked Jan 21 '15, 1:50 a.m.
edited Jan 22 '15, 10:27 p.m.
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



permanent link
Donald Nong (14.5k614) | answered Jan 22 '15, 5:19 a.m.
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,

Thank you for the suggestion but unfortunately that change just gives me an undefined value for 'module' rather than an object.
So I can only get the CONTAINING_MODULE attribute of a module artifact, but isn't that a bit redundant as it would provide an attribute of itself.
Lastly, if this method will not work, are you able to suggest any other functions I could look into using to find the module in which a base artifact is located? I've been stuck on this one a while.

Thanks,
Andrew


Donald Nong commented Jan 22 '15, 6:52 p.m.

Hi Andrew,
I did get the module in my code, but I paired it with the "TITLE" attribute and was not sure it made any difference.
If you do some network tracing (Chrome or Firebug), you will see that the query RM sends to the server when getting the "CONTAINING_MODULE" attribute is quite different from when getting the "where used" section. When getting the "CONTAINING_MODULE" attribute, it tries to get a "module" directly containing the current artifact - this only works for a module artifact. When getting the "where used" section, it tries to get resources (including collections and modules) that contain the current artifact's "bound artifacts".
I seem to recall that the current RM extension cannot retrieve "bound artifacts". If true, then unfortunately no workaround is available. Otherwise, you could have retrieved the "bound artifacts"  first and then their containing resources.

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.