Adding Relationships - Server Method

Asking with a more general title, but I'm stuck. I have a need to use a server-side method to generate relationships. Eventually I see this as an admin tool using endpoints whenever I figure out how to pass in a list of names to a method... localhost/.../server/odata/method._Add_Identities

Anyway, I run this as-is and it isn't actually adding the identities. Rather than returning the counts I can return one of the identities and see that there is what seems like a new relationship added, but it is not (new to C# -I need to learn how to return multiple items in an array in C# and Innovator) but my ask is: Why isn't the Relationship added here? NOTE: I only added the "isTemp:0" because in the resultant AML, without that, it seems to be set to true. I thought that was the problem...


string[] addToIdentities = { "All Employees", "Some Employees", "Solicitors" };
string[] memberIdentityName = { "test user", "foo bar" };
for (int h = 0; h < memberIdentityName.Length; h++) {
    // The identity that will become the new Member.
    Item newMember = this.newItem("Identity", "get");
    newMember.setProperty("name", memberIdentityName[h]);
    newMember = newMember.apply();
    for (int i = 0; i < addToIdentities.Length; i++) {
        // The identity to add Member Relationship to.
        Item identity = this.newItem("Identity", "edit");
        string where = "name = '" + addToIdentities[i] + "'";
        identity.setAttribute("where", where);
        identity = identity.apply();
        // Create Member relationship with “related_id”.
        Item relationship = identity.createRelationship("Member", "add");
        relationship.setProperty("related_id", newMember.getID());
        relationship.setAttribute("isTemp", "0");
        relationship.apply();
    }
}
//
Innovator inn = this.getInnovator();
return inn.newResult(memberIdentityName.Length.ToString() + " Identities added as Members to " + addToIdentities.Length.ToString() + " Identites");
Parents
  • I assume the line identity = identity.apply() splits your query. So you want to add realtionships when you already finished the editing of the Identity.

    -> Delete line  identity = identity.apply();
    -> Replace relationship.apply() with  identity = identity.apply();

    Use a more clearer "where" query with the name of the target database, cause 'name' is available in every table and this could also lead to conflicts. 

    --> setAttribute("where","[Identity].name = 'xyz'");

Reply
  • I assume the line identity = identity.apply() splits your query. So you want to add realtionships when you already finished the editing of the Identity.

    -> Delete line  identity = identity.apply();
    -> Replace relationship.apply() with  identity = identity.apply();

    Use a more clearer "where" query with the name of the target database, cause 'name' is available in every table and this could also lead to conflicts. 

    --> setAttribute("where","[Identity].name = 'xyz'");

Children