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 - Delete the grid item it check the Parent (part) condition

Shantha - Wednesday, May 15, 2013 7:17 AM:

Hi,
Im trying to delete the grid item it check the Parent(part)condition if the condition is
not correct it need to prompt alert and delete the relationship item. For me it prompt the message but not deleting the grid item I put in (OnInsertrow) relationship grid event.

below code is not working..(removerelationship)correct me where im doing wrong.

debugger;
var myInnov=new Innovator();
var thisItem = parent.thisItem;

var tpart=myInnov.newItem("Part","get");
var parent_part_number = parent.thisItem.getProperty("part_no");

var child = thisItem.getItemsByXPath("//Item[@id = '" + relatedID + "']").getItemByIndex(0);


var x1 = child.getProperty("item_number");

 
 if(x1!==parent_part_number)
 {
 //top.aras.AlertSuccess("Document Number is not as same as Part Number : " + x1);
 alert("Document is not tally as Part Number" +"["+ x1+"]");

 child.setProperty("thumbnail","");
child.setProperty("item_number","");
child.setProperty("major_rev","");
child.setProperty("pre_state","");
child.setProperty("generation","");
child.setProperty("state","");


thisItem.removeRelationship(child);


var objwin = top.aras.uiFindWindowEx(thisItem.getID());
 if(objwin)
 {
  objwin.updateRootItem(parent.item);
 }
 }
 else
 {
 }

But im not able to delete the child item. Im stuck here.If any one know correct me.

Thanks.

 



Brian - Wednesday, May 15, 2013 7:54 PM:

Hi Shantha,

There are a couple of things with your code that are incorrect.

The biggest problem you have is that 

thisItem.removeRelationship(child) is not being passed a relationship Item it is being passed the child item.

This code does what you want. Note that unless you have changed your properties the Part Number for a Part item type is stored as "item_number"

var myInnov = new Innovator();
var ctx = parent.thisItem;

var parent_part_number = ctx.getProperty("item_number");
var child = ctx.getItemsByXPath("//Item[@id = '" + relatedID + "']").getItemByIndex(0);

var x1 = child.getProperty("item_number");
  if(x1!==parent_part_number)
 {
alert("Document is not tally as Part Number" +"["+ x1+"]");
var partDoc = ctx.getItemsByXPath("//Item[@id='" + relationshipID + "']");
gridApplet.DeleteRow(relationshipID);
ctx.removeRelationship(partDoc);
return;  
}

Hope this helps,

Brian.



Shantha - Wednesday, May 15, 2013 10:53 PM:

Hi Brian,

Thanks for you code. Actually i attached the code in "OnInsertRow " of Relationship type. Im facing the error has Internal error:Event handler failed

Technical message :row_onInsertrow handler failed with the message: Index was outside the bound of boundary . client side error.

What is the problem is the event i selected is wrong.

Thanks,

 

 

 



rrt - Monday, May 2, 2016 12:45 AM:

hiiii , i am not able to get property of child item to compare with parent item in grid event for oninsertrow



Brian - Wednesday, May 15, 2013 11:20 PM:

Hi Shantha,

The onInsertRow is the same place that I put the code to test it.

This error is not to do with the code in the new method.

There is another method that runs OnInsertRow (IncrementSequenceNumber).

I'm guessing that you have put your new method in to run before the existing IncrementSequenceNumber method.

Make sure that the IncrementSequenceNumber method is running first and then run your new method.

Then you will not get this error.

Hope this helps,

Brian.



Shantha - Thursday, May 16, 2013 12:12 AM:

Hi Brian,

Im working on "PartCad"  on CadDocument after running first Increment Sequence number(128 sort order) then the new method(256 sort order) is made to run.

But the error is Internal error:Event handled failed

Technical message:row_insertrow handler failed with message:Object doesnt support this property or method.

I even cleared cache also.. But no result.

Thanks.

 

 



Brian - Thursday, May 16, 2013 1:48 AM:

Hi Shantha,

I haven't done much work with CAD Documents. However, I just tested the exact same code that I supplied you against the Part CAD Relationship and it works with no errors.

Do you have any other code running on rowInsert or create new or anywhere that might be causing this problem?

This is a different error message than before so something is happening somewhere that does not appear to be part of the code we have just added.

Take the code out and try to add a CAD Document to a part and make sure everything works without this code in place.

Do you have anything else that is supposed to run after this code?

Maybe that is where the problem is.

I strongly suggest you set up client side debugging so that you can trace through this code to see where it is failing.

Cheers,

Brian.