The following is a Gateway script example which iterates over all of the roles and tries to find a resource that has the same id field. If one is found, the script will then search for a resource role matching the existing resource and role object id fields. If no match is found or there is no resource role for this role/resource, a new resource role object will be created and added.
for (role : <Role>) {
<Resource> resource = <Resource>.findOne(r -> ( r.Id == role.Id ));
if (resource != null) {
<ResourceRole> myrr = <ResourceRole>.findOne(rr -> ((rr.ResourceObjectId == resource.ObjectId) && (rr.RoleObjectId == role.ObjectId)));
if (myrr == null ) {
<ResourceRole> resRole = new <ResourceRole>;
resRole.ResourceObjectId = resource.ObjectId;
resRole.RoleObjectId = role.ObjectId;
resRole.ObjectId = -100;
add resRole;
}
}
}
delete <Role>;
delete <Resource>;