Share all details about your problem, including any error messages you may have received.
Is there a way to programmatically create Scope objects from a rule?
I have created few from Global settings. Now my requirement is to create new scope from a rule.
Is that possible? If so, please share sample code
You can use a simple rule to execute it and create scopes
import sailpoint.object.Scope;
Scope newScope = new Scope();
newScope.setName("MyNewScope");
newScope.setDisplayName("MyScope DisplayName");
newScope.setManuallyCreated(true);
// If you want to set it in the hierarchy
newScope.setPath("SCOPE1/SCOPE2/SCOPE3");
Scope childScope = context.getObject(Scope.class,"ChildScope");
// If you want to make new scope a parent to already existing ones
newScope.setChildScopes(childScope);
context.saveObject(newScope);
context.commitTransaction();
@kjakubiak Hi, thanks for your response
Tried your suggestion, but it gave me below error:
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [sailpoint.object.Scope#c0a81dec91b61df18191b832572402d1] BSF info: Run Rule 1 - Create Scope at line: 0 column: columnNo
The code I tried is
Scope allScope = context.getObjectByName(Scope.class,"All");
List childScopes = allScope.getChildScopes();
String allScopePath = allScope.getPath();
Scope newScope = new Scope();
newScope.setName("testScope");
newScope.setManuallyCreated(true);
context.saveObject(newScope); // to generate id of newScope
newScope.setPath(allScopePath + ":" + newScope.getId());
newScope.setAssignedScopePath(allScopePath + ":" + newScope.getId());
childScopes.add(scope);
allScope.setChildScopes(childScopes);
context.saveObject(newScope);
context.commitTransaction();