pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 8:54am
1
I have created a form which has two radio buttons.
“Self” and “Others”
When Others is selected I am displaying a new field which displays identities with particular worker type using
filterString="workertype == "Employee""
I need someting similar when I select “self” radio button, But in this first I need to check if identities with particular worker type is owned by the requester i.e. the one who is selecting self radio button which is me in this case.
Below is the code which I used till now in this form. what should I proceed with in “Field_2” AllowedAttributes column to achieve this?
<Section label="Requesting For" name="Section 1">
<Field displayName="Select" name="Field_1" postBack="true" required="true" type="string">
<AllowedValuesDefinition>
<Value>
<List>
<String>Self</String>
<String>Others</String>
</List>
</Value>
</AllowedValuesDefinition>
</Field>
<Field displayName="Select Employee SSO ID" dynamic="true" name="Field_2" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Self".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
</Field>
<Field displayName="Enter Employee SSO ID" dynamic="true" filterString="workertype == "Employee"" name="Field_3" postBack="true" required="true" type="sailpoint.object.Identity">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Others".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
</Field>
<Field displayName="Manager" dynamic="true" name="Field_5" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Others".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
<Script>
<Source>import sailpoint.object.*;
import sailpoint.tools.Util;
String managerName="";
Object field3=form.getField("Field_3").getValue();
if(field3!=null){
String identityId=(String)field3;
if(Util.isNotNullOrEmpty(identityId)){
Identity idenObj = context.getObjectById(Identity.class, identityId);
if (idenObj != null)
{
if(idenObj.getAttribute("hrsupervisorname")!=null)
managerName=idenObj.getAttribute("hrsupervisorname");
}
}
}
return managerName;</Source>
</Script>
</Field>
</Section>
vedeepak
(Deepak Vema)
August 28, 2024, 9:19am
2
You can do same thing on “Field_2” like “Field_3” is defined like below
<Field displayName="Select Employee SSO ID" dynamic="true" name="Field_2" postBack="true" required="true" filterString="workertype == "Employee"" type="sailpoint.object.Identity">
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 9:23am
3
HI @vedeepak
Will it automatically satisfy the condition for Field_2 i.e. the identity should be owned by the requester and also should be Employee type?
vedeepak
(Deepak Vema)
August 28, 2024, 9:48am
4
Update the filterString entry as per the requirement and “context.getUserName()” will give you the current logging person or Requester name.
<Field displayName="Select Employee SSO ID" dynamic="true" name="Field_2" postBack="true" required="true" type="sailpoint.object.Identity">
<Attributes>
<Map>
<entry key="filterString">
<value>
<Script>
<Source>
import sailpoint.object.Filter;
import sailpoint.object.Identity;
Field field = form.getField("Field_2");
if (field == null)
return;
Identity launcherObj = context.getObjectByName(Identity.class, context.getUserName());
Filter f1 = Filter.eq("Manager.name", launcherObj.getName());
f1 = Filter.and(f1, Filter.eq("workertype", "Employee"));
field.setFilterString(f1.toString());
</Source>
</Script>
</value>
</entry>
<entry key="hidden">
<value>
<Script>
<Source>
import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Self".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;
</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
</Field>
Arun-Kumar
(Arun Kumar)
August 28, 2024, 10:06am
5
Hi @pctripathi ,
context.getUser() method return the self user name. With help of this, you can populate the required value.
<Field displayName="Select NPIdentity SSO ID" dynamic="true" name="Field_2" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Self".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
<Script>
<Source>
import sailpoint.object.*;
String userName= context.getUserName();
Identity id = context.getObjectByName(Identity.class,userName);
return id.getAttribute("workerType");
</Source>
</Script>
</Field>
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 10:14am
6
Hi @Arun-Kumar
Tried your code. But changes did not took effect. Still Field_2 is unhiding and displaying as simple field. It’s not listing the “NPIdentity” worker type identities which are owned by the current user/requester.
vedeepak
(Deepak Vema)
August 28, 2024, 10:28am
7
My bad above one is wrong. property name starts with smallcase. below one is correct
Filter f1 = Filter.eq("manager.name", launcherObj.getName());
Arun-Kumar
(Arun Kumar)
August 28, 2024, 10:32am
8
Hi @pctripathi ,
I am just return the logging user workerType. you can modify the logic as per your need. sample code for reference
import sailpoint.object.*;
String userName= context.getUserName();
Identity id = context.getObjectByName(Identity.class,userName);
String worker= id.getAttribute("workerType");
QueryOptions qp = new QueryOptions();
qp.addFilter(Filter.eq("workerType",worker));
Iterator iter = context.search(Identity.class,qp);
List identityList=new ArrayList();
while(iter.hasNext()){
identityList.add(iter.next().getName());
}
return identityList;
Regards,
Arun
1 Like
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 12:08pm
9
Hi @Arun-Kumar
Am I doing this correct?
<Field displayName="Select NPIdentity SSO ID" dynamic="true" name="Field_2" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Self".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
<Script>
<Source>
import sailpoint.object.*;
String userName= context.getUserName();
Identity id = context.getObjectByName(Identity.class,userName);
String worker= id.getAttribute("NPIdentity");
QueryOptions qp = new QueryOptions();
qp.addFilter(Filter.eq("workerType",worker));
Iterator iter = context.search(Identity.class,qp);
List identityList=new ArrayList();
while(iter.hasNext()){
identityList.add(iter.next().getName());
}
return identityList;
</Source>
</Script>
</Field>
1 Like
Arun-Kumar
(Arun Kumar)
August 28, 2024, 12:12pm
10
Hi @pctripathi ,
I hope “NPIdentity” is an identity attribute and marked as searchable in your environment.
Did you try with this code? Getting any error?
Regards,
Arun
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 12:22pm
11
Yes @Arun-Kumar NPIdentity is an identity attribute like for an identity workerType is set as NPIdentity. I tried your given code. Wrote this like this
import sailpoint.object.*;
String userName= context.getUserName();
Identity id = context.getObjectByName(Identity.class,userName);
String worker= id.getAttribute("NPIdentity");
QueryOptions qp = new QueryOptions();
qp.addFilter(Filter.eq("workerType",worker));
Iterator iter = context.search(Identity.class,qp);
List identityList=new ArrayList();
while(iter.hasNext()){
identityList.add(iter.next().getName());
}
return identityList;
Form is showing system error when I try to open.
1 Like
Arun-Kumar
(Arun Kumar)
August 28, 2024, 12:24pm
12
Hi @pctripathi ,
Could you please share the screen shot of NPIdentity attribute from identity mappings?
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 12:30pm
13
Hi @Arun-Kumar
NPIdentity is not metioned in identity attribute mapping. Instead NPI identity is listed as workerType in Identity attributes
Instead I saw the attribute name of worker Type as workertype.
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 12:43pm
14
Hi @Arun-Kumar
Actually the form is for someone who is requesting creation of accounts. So here suppose I am the requester then I will select self radio button. And that radio button will display a field which will show identities that are already owned by me. So I could select those identities. And the Identities which are being displayed must particularly be workerType NPIdentity. And I should be able to select it.
Arun-Kumar
(Arun Kumar)
August 28, 2024, 12:43pm
15
Hi @pctripathi ,
You can return the workertype value directly.
import sailpoint.object.*;
String userName= context.getUserName();
Identity id = context.getObjectByName(Identity.class,userName);
String worker= id.getAttribute("workertype");
return worker;
1 Like
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 1:06pm
16
Hi @vedeepak
I tried modifying the code. It’s still showing system error when trying to open form after adding the script.
1 Like
vedeepak
(Deepak Vema)
August 28, 2024, 1:11pm
17
I have used below code and it is working. I commented out workertype, please config as per your attribute name
<Field displayName="Select Employee SSO ID" dynamic="true" name="Field_2" postBack="true" required="true" type="sailpoint.object.Identity">
<Attributes>
<Map>
<entry key="filterString">
<value>
<Script>
<Source>
import sailpoint.object.Filter;
import sailpoint.object.Identity;
var field = form.getField("Field_2");
if (field == null)
return;
Identity launcherObj = context.getObjectByName(Identity.class, context.getUserName());
var f1 = Filter.eq("manager.name", launcherObj.getName());
//f1 = Filter.and(f1, Filter.eq("workertype", "Employee"));
log.error("launcherObj"+launcherObj.getName()+".... " +f1.toString());
field.setFilterString(f1.toString());
</Source>
</Script>
</value>
</entry>
<entry key="hidden">
<value>
<Script>
<Source>
import sailpoint.object.Field;
Field f1 = form.getField("Field_1");
String f1value = f1.getValue();
boolean hideField = false;
if(!("Self".equalsIgnoreCase (f1value))) {
hideField= true;
field.setRequired(false);
}
else {
field.setRequired(true);
}
return hideField;
</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
</Field>
If you’re getting error, can you see syslogs with incident code in advance analytics page.
2 Likes
pctripathi
(Pratik Chandra Tripathi)
August 28, 2024, 4:38pm
18
Thanks @vedeepak . Its working
1 Like
vedeepak
(Deepak Vema)
August 29, 2024, 4:13am
19
Welcome @pctripathi . Happy learning
system
(system)
Closed
October 28, 2024, 4:13am
20
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.