Display Relationship data in a form

Hello, I would like to create my custom print view for an Item, for that i created a form triggered on the print event, but i would like to display in addition of the regular fields of the item, all the related items from its relationships. Any ideas on how i can do that? Thank you. Léo
  • Hi Leo, I think this could best be accomplished by adding an HTML Field to your print view that can query for the relationships. As an example, I used the sample below from an HTML Field on a form to pull the item_numbers from the Part BOM relationship and displayed them in the main form. Chris _______________________ Christopher Gillis Aras Labs Software Engineer
  • Hi Christopher ,
     I used the sample below from an HTML Field on a form to pull the item_numbers from the Part BOM relationship and displayed them in the main form.
    Looks like you forgot to include your code to your post :p, could you post this example's code so i can see how you did it. Léo
  • Hi Leo, That's odd that you're unable to see the embedded Gist. Regardless, I am including both a link to the gist below as well as the text of the code below that. https://gist.github.com/cgillis-aras/c1aa8a7d3696c6c2f8d3d4ff1ae54e37
    <script type="text/javascript">
        showRelatedItems = function() {
    		var part = document.thisItem;
    		var relationships = aras.getRelationships(part.node, "Part BOM");
    		var container = document.getElementById("relatedItemContainer");
    		for (var i = 0; i < relationships.length; i++)
    		{
    			var relItem = aras.getRelatedItem(relationships[i]);
    			var relItemNum = aras.getItemProperty(relItem, "item_number");	
    			var newDiv = document.createElement("div");
    			newDiv.setAttribute("class", "related_item");
    			newDiv.innerHTML = relItemNum;
    			container.appendChild(newDiv);
    		}
    	}
    window.addEventListener("load", showRelatedItems);
    </script>
    <div id="relatedItemContainer"></div>
    
  • Hi Christopher, Thank you for your help this was exactly what i was looking for. However i have been looking at a realy odd issues for days now : When i lock or unlock an item, if i dont open the realtionship tab of the Relationship i want to display, the aras.getRelationships(item.node, "RELATIONSHIP"); returns an empty array. For example if my item has 3 relationships tabs RELATIONSHIP1, RELATIONSHIP2, RELATIONSHIP3 If RELATIONSHIP2 tab is selected, i lock the item, close it, then open the item again i have : aras.getRelationships(item.node, "RELATIONSHIP1"); //returns array [] aras.getRelationships(item.node, "RELATIONSHIP2"); //returns array [item1,item2,...] aras.getRelationships(item.node, "RELATIONSHIP3"); //returns array [] if i then open the relationship3 tab, close the item, open it again aras.getRelationships(item.node, "RELATIONSHIP3"); will return me the related items. It looks like the related items have to be "loaded" once in the Relationship tab before i can get them in my js script. Any idea how i can solve this issue? i hope i have been clear, i can give you more infos / screenshots if needed. Thank you. Léo