Managing 'memberOf' Relationships Based on Organization Name

Hi @stephane.orluc ,

Thank you so much for your response… through that we can able to assign users to organization through bulk load. But we got the scenario where we need to assign users to multiple organization while bulk load.
I tried to use this code but it’s not doing it somewhere I am getting error. Can you provide me a workaround if possible.

Thank you in advance

1 Like

Hi @stephane.orluc ,

Thank you for your previous response using that I could able to achieve the requirement… I have got one requirement that lets say if I create a relationship based on organization name if update is required I need to remove previous relationship i.e., remove the previously configured “memberOf” data and create new relation.

Need ur assistant! Thank u in response…

hi @Suriya
To do that, instead of patching the object with "operation":"add" I think I would use "operation":"replace". Or I’ll do it with 2 steps : 1/ "operation":"remove", 2/ "operation":"add".
Regards,
Steph

1 Like

Hi @stephane.orluc ,

Thank you for your inputs. I have tried this but since it is object operation BTW I don’t know that may be the reason it’s not removing or replacing it.
For me this scenario is used in two different places

  1. One parent-child organization relationship, where I need to remove previous relation and create new one.
  2. users-organization relationship, where I need to remove the previous relationships (because user’s maybe the member of different organization).
    In simple terms, removing previous one is required, adding we can utilize existing set of codes.

Looking for you suggestion! Thanks in advance

Hi @stephane.orluc and everyone,

Looking for your help! Thanks in advance…

@suriya Is it the remove operation that does not work? This operation is particular in that you need to pass in the entire relationship object in the value to remove as specified here: Knowledge - ForgeRock BackStage

Hi @patrick_diligent ,

The current flow I am following is when admin creates new user in the Form (created through journey) provide the organization name so post creation I have used the below script with “operation:add” to create relationship.
var orgname = object.organizaton_name;
var org = openidm.query(“managed/alpha_organization”,{ “_queryFilter”: “name sw "”+orgname+“"”},[“_id”]);
if(org){
var patchedUser = openidm.patch(“managed/alpha_user/” + object._id, null, [{
“operation”:“remove”,
“field”:“/memberOfOrg/-”,
“value”:{“_ref”:“managed/alpha_organization/”+org.result[0]._id+“”,“_refProperties”:{}}
}]);
}

So I have applied “remove” in above operation field which does not remove the previous relationship. I even used “replace” as suggested but it does not do any changes.
Please have a look on the above script and provide suggestion if anything needed.

Thank you in advance!

To remove you have to pass revision id (rev) as well as a parameter in your openidm.patch call.

But the above operation is working for “/parent” object for changing parent organization.
I am facing issue only in “/memberofOrg/-” where I guess multiple selections are possible. So I need to understand that specific change required for this operation i.e., removing all previous relation and add one. Adding one is not issue for me but removing is where I am facing issue

Hi @Suriya see whether How to remove User -> Organization relation through script in Event hooks? answers your question

1 Like