Need a Callback for a Relationships Grid Row Event

You want to call a client side Method when the Relationships Grid row is selected to deselect the row if it is not a new relationship row.

Technique

Add the Grid Event relationship to a Method as the callback for the OnSelectRow event.

The Method gets three arguments: relationshipID, relatedID and gridApplet. The relationshipID is the ID for the relationship Item for the selected row. The relatedID is the ID for the related Item for the selected row. The gridApplet is a handle to the grid control object.

The relationshipID is also the ID for the grid control row. This recipe calls the gridApplet Deselect() method if the relationship Item for the selected row has not been modified.

JavaScript

// The row ID is the same as the relationship ID

var rowId = gridApplet.getSelectedId();

// Find the relationship item and exit if it’s not found

var thisItem = parent.thisItem;

var xpath = “Relationships/Item[@id='" + rowId + "']";

var relItem = thisItem.getItemsByXPath(xpath);

if (relItem.getItemCount() == 1) {

relItem = relItem.getItemByIndex(0);

} else {

return;

}

// Check the isDirty attribute to see if the relationship has been modified

var isDirty = (relItem.getAttribute(“isDirty”) == “1");

if (!isDirty) { gridApplet.Deselect(); }