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

How to delete relation ship before edit

Hi guys

New a method like this

Item mainItem = this.newItem("MainItem", "get");
mainItem.setID("SysID");
mainItem = mainItem.apply();

//Add Relationship
var relItem = innovator.newItem("Detail_File","add");
relItem.setProperty("related_id","fileID_A");
mainItem.addRelationship(relItem) ;

var relItem = innovator.newItem("Detail_File","add");
relItem.setProperty("related_id","fileID_B");
mainItem.addRelationship(relItem);

//delete relationship
//I want to delete fileID_A Relation  (But right now not save in DB so i can't get fileID_A Sys ID to delete)

mainItem=mainItem.apply("edit");

How can I do?

Parents
  • Hello Michelle,

    You can delete the relationship from this structure before you apply the item by using mainItem.removeRelationship(relItem);. The removeRelationship function expects an argument of an Item object, so you will first need to get the item you want to delete. Presumably, you're performing some kind of check to determine when the item should be deleted, so your code could look something like this:

        Item relFiles = mainItem.getRelationships("Detail_File");
        
        for (int i = 0; i < relFiles.getItemCount(); i++)
        {
            Item relFile = relFiles.getItemByIndex(i);
            // do your logic on relFile here
            // if (relFile.getProperty("XXX") != "XXX")
            mainItem.removeRelationship(relFile);
        }

    Chris

    Christopher Gillis

    Aras Labs Software Engineer. 

Reply
  • Hello Michelle,

    You can delete the relationship from this structure before you apply the item by using mainItem.removeRelationship(relItem);. The removeRelationship function expects an argument of an Item object, so you will first need to get the item you want to delete. Presumably, you're performing some kind of check to determine when the item should be deleted, so your code could look something like this:

        Item relFiles = mainItem.getRelationships("Detail_File");
        
        for (int i = 0; i < relFiles.getItemCount(); i++)
        {
            Item relFile = relFiles.getItemByIndex(i);
            // do your logic on relFile here
            // if (relFile.getProperty("XXX") != "XXX")
            mainItem.removeRelationship(relFile);
        }

    Chris

    Christopher Gillis

    Aras Labs Software Engineer. 

Children
No Data