This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Prevent user from creating a relationship until the parent item is complete:

Yelena - Thursday, May 21, 2009 12:31 PM:

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
 


tstickel - Thursday, May 21, 2009 4:48 PM:

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.



Yelena - Friday, May 22, 2009 12:04 PM:

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 

 

 

var

 

 

if 

 

 

(!rfq_number) { a.AlertError("'You are required ......before creating a new relationship>."); return false; }
rfq_number = parent.thisItem.getProperty("rfq_number");
thisItem = parent.thisItem;

 



Yelena - Friday, May 22, 2009 12:07 PM:

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. 

 

 

 

 

 

 

 

 

 

 

 

var 

 

 

var rfq_number = parent.thisItem.getProperty("rfq_number");

if 

 

 

(!rfq_number) { a.AlertError("'You are required ...before creating a new relationship."); return false; }
thisItem = parent.thisItem;



tstickel - Friday, May 22, 2009 12:39 PM:

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.



tstickel - Friday, May 22, 2009 12:44 PM:

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



Yelena - Friday, May 22, 2009 2:45 PM:

Terry,

inItem.removeRelationship(thisRel); statement worked just fine.

Thanks a lot for your help