Can you Remove xClass relationship with onChange field event?

I'm trying to clear out the xClass relationship when the class of a part is changed.  The code I have below is ran on the filed event of the drop down onChange, however it doesn't remove the xClass relationship.  

var rootItem = document.thisItem;
rootItem.fetchRelationships("Part_xClass");
var xClassRelationship = rootItem.getRelationships("Part_xClass");

if(xClassRelationship.getItemCount() > 0){
    var current = xClassRelationship.GetItemByIndex(0);
    rootItem.removeRelationship(current);
}

return rootItem;

Parents
  • Hi Robert

    Yes, you can remove the xClass relationship. small change to your code will work

    var rootItem = document.thisItem;

    var xClassRelationship = rootItem.getRelationships("Part_xClass");

    for (var i = 0; i < xClassRelationship.getItemCount(); i++)

    {

    var current = xClassRelationship.getItemByIndex(i);

    current.setAction('delete');

    }

    Thank You

    Gopikrishnan R

Reply
  • Hi Robert

    Yes, you can remove the xClass relationship. small change to your code will work

    var rootItem = document.thisItem;

    var xClassRelationship = rootItem.getRelationships("Part_xClass");

    for (var i = 0; i < xClassRelationship.getItemCount(); i++)

    {

    var current = xClassRelationship.getItemByIndex(i);

    current.setAction('delete');

    }

    Thank You

    Gopikrishnan R

Children
No Data