Get parent of context item in relationship action

オフライン

Hi all,

I am using an action from a relationship grid which is driven by the PE_GetSelectedItems method. I need to get a handle on the parent item specifically as it looks like "this" returns a collection of all items open when used from this kind of action. 

In my case, I thought to get the parents via relationship however the item selected may have multiple parent items from the same relationship where I need the one this method is specifically called from.

Any help is appreciated. 

Parents
  • rItem.getProperty("source_id");

    or i misunderstood?

  • 0 オフライン in reply to alaxala

    I thought of this however of the relationship item I am trying to capture the parent of may have multiple parent relationships.

    As far as I know, the PE_GetSelectedItems will return the item selected in the grid so I am wondering how to specifically get the parent which is active when I use my action that captures the context item via PE_GetSelectedItems

  • 0 オフライン in reply to Morgan

    Ok. I understood.

    PE_GetSelectedItems returns related items if it called from relationships grid. Well, you can use your own modified version of PE_GetSelectedItems for this action. All you need is comment out lines 84-86 in the original:

    if (ccItem) {
    	ccItem = aras.getRelatedItem(ccItem);
    }
    

    You get the relationship items instead of related items and can use source_id property.

    Or, if you need both, you can use fake property:

    if (ccItem) {
        var parent = ccItem.getPropertyItem("source_id");
    	ccItem = aras.getRelatedItem(ccItem);
    	ccItem.setPropertyItem("parent", parent);
    }

  • 0 オフライン in reply to alaxala

    Thanks for this. I do need both properties however when trying to set a fake property to pass, the PE_GetSelectedItems method fails with the error aras_object: "undefined" : "undefined"

  • 0 オフライン in reply to Morgan

    Sorry, I forgot as always that Javascript Item class is not the same as server-side Item class. Try this:

    if (ccItem) {
    	var source = ccItem.selectSingleNode("source_id");
    	ccItem = aras.getRelatedItem(ccItem);
    	ccItem.appendChild(source);
    }
    

    You get the parent item as "source_id" property.

  • 0 オフライン in reply to alaxala

    Thanks for responding again. Even with these changes, the same failure error is presented.

  • 0 オフライン in reply to Morgan

    It is very strange. I tried it myself. It works. Maybe you are changing the wrong block. There is a similar section of code above. Here is bigger piece of PE_GetSelectedItems with changes:

    if (isRelationship) {
    	var parentId = this.getProperty("source_id", "");
    	var parentItem = aras.getItemById(sourceItemTypeName, parentId, 0);
    	if (parentItem) {
    		ccItem = parentItem.selectSingleNode("Relationships/Item[@id='" + idArray[k] + "']");
    
    		//If item isn't cached, get 
    		if (!ccItem) {
    			ccItem = aras.getItemById(thisType, idArray[k], 0);
    		}
    
    		//get related Part
    		if (ccItem) {
    			var source = ccItem.selectSingleNode("source_id"); // add this
    			ccItem = aras.getRelatedItem(ccItem);
    			ccItem.appendChild(source);     // and this
    		}
    	}
    }
    

  • 0 オフライン in reply to alaxala

    I think I am a little closer. I have noticed that if I ran the method twice, it runs ok the first time, but fails the second time. If I refresh the parent, it is working fine again. I think I will need to add a refresh into my method. Going to try this.

    Also, I am assuming I should be able to reference this property on the subsequent called method via the item.getProperty("source_id") or should I use .getPropertyItem()?

  • +1 オフライン in reply to Morgan

    I found the problem. XmlNode.appendChild() moves the node, not copy. And next time the ccItem no longer has the property "source_id" and "source" becomes undefined.

    This is final version, I hope )). I also added a check for re-adding a "source_id" property.

    if (ccItem) {
    	var source = ccItem.selectSingleNode("source_id").cloneNode(true);
    	ccItem = aras.getRelatedItem(ccItem);
    	if (!ccItem.selectSingleNode("source_id")) ccItem.appendChild(source);
    }
    

    If you use item.getProperty you get the string with parent item id. If you use getPropertyItem you get parent item. But with only "type", "keyed_name" attributes and "id" property. It will not have any more properties since they were not in the original "source_id" property.

Reply
  • +1 オフライン in reply to Morgan

    I found the problem. XmlNode.appendChild() moves the node, not copy. And next time the ccItem no longer has the property "source_id" and "source" becomes undefined.

    This is final version, I hope )). I also added a check for re-adding a "source_id" property.

    if (ccItem) {
    	var source = ccItem.selectSingleNode("source_id").cloneNode(true);
    	ccItem = aras.getRelatedItem(ccItem);
    	if (!ccItem.selectSingleNode("source_id")) ccItem.appendChild(source);
    }
    

    If you use item.getProperty you get the string with parent item id. If you use getPropertyItem you get parent item. But with only "type", "keyed_name" attributes and "id" property. It will not have any more properties since they were not in the original "source_id" property.

Children
No Data