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

rated by 0 users
This post has 6 Replies | 0 Followers

Top 50 Contributor
Posts 36
Points 425
Yelena Posted: Thu, 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

 

Yelena
Top 25 Contributor
Posts 86
Points 1,295
tstickel replied on Thu, 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.

Terry Stickel, PDM Consultant

TStickel Consulting

Sanibel, Florida

  • | Post Points: 20
Top 50 Contributor
Posts 36
Points 425
Yelena replied on Fri, 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
Top 50 Contributor
Posts 36
Points 425
Yelena replied on Fri, 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;

Yelena
  • | Post Points: 20
Top 25 Contributor
Posts 86
Points 1,295
tstickel replied on Fri, 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.

Terry Stickel, PDM Consultant

TStickel Consulting

Sanibel, Florida

  • | Post Points: 5
Top 25 Contributor
Posts 86
Points 1,295
tstickel replied on Fri, 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

Terry Stickel, PDM Consultant

TStickel Consulting

Sanibel, Florida

  • | Post Points: 20
Top 50 Contributor
Posts 36
Points 425
Yelena replied on Fri, May 22 2009 2:45 PM

Terry,

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

Thanks a lot for your help

Yelena
  • | Post Points: 5
Page 1 of 1 (7 items) | RSS