I am trying to write a method that will prevent user from creating a relationship before some fields are populated on the parent form. I managed to get an alert, but how can I prevent creation of the new relationship? It still appears as an empty line and user can save it. In other word I would like to have a method that alerts user that relationship can not be created when users attempts to enter a new relationship, but does not create it ( or deletes it after alert)
So here is a javascript method:
//This method sets the child properties 'RFQ Plant Feasibility.<property_name>' property value from the parent
//'RFQ.product_type' property value.
var a = top.aras;
var thisItem = parent.thisItem;
var rfq_number = parent.thisItem.getProperty("rfq_number");
if (!rfq_number) { a.AlertError("'You are required to save <b>PAR</b> before creating a new <b>Plant Feasibility</b>"); return; }
var delivery_terms =
if (!delivery_terms ) { a.AlertError("'The <b>Delivery Term</b> field is required prior creating a new Plant Feasibility"); return; }
var child = thisItem.getItemsByXPath("//Item[@id='" + relatedID + "']").getItemByIndex(0);
child.setProperty("rfq_number",rfq_number);
child.setProperty("delivery_terms",delivery_terms);
var objwin = top.aras.uiFindWindowEx(thisItem.getID());
if (objwin) {
objwin.updateRootItem(parent.item); // refresh grid with new entries
}
Thanks for your help
Yelena
Yelena;
Without reading all of your code in detail, I believe that all you need to do is to return false; after your AlertError instead of just a return;
The return false; triggers the Innovator grid object to abort the row insert.
Terry Stickel, PDM Consultant
TStickel Consulting
Sanibel, Florida
Hello Terry. Thanks for response.
I made a change below. I am getting an alert, but when click OK the row is still there.
The method executed as a grid event OnInsertRow
var
if
OOPS! It does not look right. Here is a code.
Again - I am getting an alert, but when click OK the row is still there.
Sorry, I looked at some code I had previously written to handle this and found out it was triggered on a onBeforeNew event for the relationship that was being presented in the gird. So it was not a grid OnInsertRow event. I am still sure it can be handled via the OnInsertRow event and will look for an example.
I found it:
.......
var inItem = parent.thisItem;var thisRel = inItem.getItemsByXPath("//Item[@id='" + relationshipID + "']").getItemByIndex(0);var thisItem = parentItem.getItemsByXPath("//Item[@id='" + relationshipID + "']").getItemByIndex(0).getRelatedItem();
if (topItem.getProperty("classification").indexOf("/Part/Component") > -1) { alert("You can not add any part to a Component's BOM"); inItem.removeRelationship(thisRel); var objwin = top.aras.uiFindWindowEx(parentItem.getID()); if (objwin) { objwin.updateRootItem(parent.item); // refresh grid with new entries }}
So the key is the inItem.removeRelationship(thisRel); statement
Terry,
inItem.removeRelationship(thisRel); statement worked just fine.
Thanks a lot for your help