Show particular accounts that are under me

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 == &quot;Employee&quot;" 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>

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 == &quot;Employee&quot;" type="sailpoint.object.Identity">

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?

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>

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>

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.

My bad above one is wrong. property name starts with smallcase. below one is correct

Filter f1 = Filter.eq("manager.name", launcherObj.getName());

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

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

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

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

Hi @pctripathi ,

Could you please share the screen shot of NPIdentity attribute from identity mappings?

Hi @Arun-Kumar

NPIdentity is not metioned in identity attribute mapping. Instead NPI identity is listed as workerType in Identity attributes
image

Instead I saw the attribute name of worker Type as workertype.

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.

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

Hi @vedeepak
I tried modifying the code. It’s still showing system error when trying to open form after adding the script.

1 Like

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

Thanks @vedeepak. Its working

1 Like

Welcome @pctripathi. Happy learning :slightly_smiling_face:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.