Read user's ID and retrieve its manager's detail

I have made a from in sailpoint which asks for user information as shown below.


When selecting “My Self” radio button, the next field will automatically fill requester ID.
And when “Other User” radio button is selected the field becomes a dropdown which contains all Sailpoint ID’s. in which accounts and can be selected.

Code for the same is given below.

<Section label="User Information" name="Section 1">
    <Field displayName="Requested For" displayType="radio" dynamic="true" name="Field 1" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Value>
          <List>
            <String>Myself</String>
            <String>Other User</String>
          </List>
        </Value>
      </AllowedValuesDefinition>
    </Field>
    <Field displayName="Requestor" dynamic="true" name="Field 20" postBack="true" required="true" type="string" value="script: context.getUserName();">
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>
                  import sailpoint.object.*;
                  Field f1 = form.getField("Field 1");
                  if(f1!=null){
                  String selected = f1.getValue();
                  log.error("Select"+selected);
                  if (selected!=null &amp;&amp; selected.equalsIgnoreCase("Myself")){
                	 form.getField("Field 20").setRequired(true);
                  return false;
                  }else{
                  
                   form.getField("Field 20").setRequired(false);
                           return true;
                  }
                  }
                  return "";
								</Source>
              </Script>
            </value>
          </entry>
          <entry key="valueProperty" value="context.getUserName()"/>
        </Map>
      </Attributes>
    </Field>
  </Section>
  <Section name="OtherUser">
    <Field displayName="Requestor" dynamic="true" filterString="(inactive == false &amp;&amp; correlated == true &amp;&amp; email.notNull()) || workgroup == true" name="OthersRequestors" type="sailpoint.object.Identity">
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>
                   import sailpoint.object.*;
                    Field f1 = form.getField("Field 1");
                    if(f1!=null){
                    String selected = f1.getValue();
                    if (selected!=null &amp;&amp; selected.equalsIgnoreCase("Other User")){
					              form.getField("OthersRequestors").setRequired(true);
                          return false;
                   }else{
                   form.getField("OthersRequestors").setRequired(false);
                          return true;
                  }
								}
								</Source>
              </Script>
            </value>
          </entry>
          <entry key="valueProperty" value="name"/>
        </Map>
      </Attributes>
      <ValidationScript>
        <Source>
          if (value.size() > 10) { return "Maximum 10 users can be selected"; }
          else { return null; }
        </Source>
      </ValidationScript>
    </Field>
  </Section>

I want to add one more field below requester field which will automatically show manager’s detail of the selected requester.

Hi @pctripathi ,

I just put this together now and isn’t tested, but think it gives you an idea on the approach.

  <Field displayName="Manager" dynamic="true" filterString="(inactive == false &amp;&amp; correlated == true &amp;&amp; email.notNull())" name="OtherRequestersManager" type="sailpoint.object.Identity">
    <Attributes>
      <Map>
        <entry key="hidden">
          <value>
            <Script>
              <Source>
              import sailpoint.object.*;
              
              Field f2 = form.getField("Field 20");
              Field f1 = form.getField("Field 1");
              Field f3 = form.getField("OtherRequesters");
              
              if(f2 != null)
              {
                String selected = f2.getValue();
                if (selected != null &amp;&amp; fi.getValue().equalsIgnoreCase("Other User"))
                {
                  form.getField("OtherRequesterManager").setRequired(true);
                  form.getField("OtherRequesterManager").setValue(f3.getValue().getManager());
                  
                  return false;
                }
                else
                {
                  form.getField("OtherRequstersManager").setRequired(false);
                  return true;
                }
              }
              </Source>
            </Script>
          </value>
        </entry>
        <entry key="valueProperty" value="name"/>
      </Map>
    </Attributes>
  </Field>

Thanks,

2 Likes

Hi @dylanfoggan
I tried your part of script. Did some required changes. Form received an error and did not not open. Then I tried your code as it is. But still does not seem to work in the form.

@pctripathi
Can you be more clear , you are allowing to select more than one requester, so what is your expectation for the new field as the managers can be different for each user, if you provide what exactly is needed here, can provide a solution accordingly, please help with this details.

1 Like

Hi @iamksatish
I’ll explain how this code is working

There is a field which will unhide and show requester detail when “My Self” radio button is selected otherwise it will be hidden.
In next section I have made another field that is allowing me to choose requester only if “Other User” radio button is selected, otherwise it will remain hidden.

Now I need to auto populate manager details by getting the userID of the requester in another field just below requester field.

The approach I was thinking is that -
(Field 20 = the field which is autopopulating itself on selecting “My Self” radio button)
There will be a field below field 20 which will check if field 20 is null. If not null it will read the user ID and display its supervisor’s name in it, otherwise hidden.

Same goes with “Other requester” field which will also have another field below it and will check for any ID on above field in order to find supervisor, otherwise stays hidden.

Okay got it, please share the complete current workflow or form xml , will share the updated code for this use case.

1 Like

Okay @iamksatish
I’ll share the files with you in personal chat

Add the below field under your form field of OthersRequestors, this should help, if not let me know

<Field displayName="Requestor Manager" dynamic="true" name="OthersRequestorsManager" type="string">
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>
                    import sailpoint.tools.Util;
                if(Util.isNotNullOrEmpty(OthersRequestors) ){
                return false;
                }
                return true;
				
								</Source>
              </Script>
            </value>
          </entry>
        </Map>
      </Attributes>
        <Script>
        <Source>
          import sailpoint.object.*;
          if(Util.isNotNullOrEmpty(OthersRequestors) ){
          {
          Identity idenObj = context.getObjectByNameIdentity.class, OthersRequestors);
          if (idenObj != null)
          {
          if(idenObj.getManager()!=null)
		  return idenObj.getManager().getName();
          }
          } 
		  }
        </Source>
      </Script>
    </Field>
1 Like

Hi @iamksatish
Had form did not work after using above code. Sent you the form in personal chat.

Hi Pratik,

Please try with below code and let me know, if you find any issue.


regards,
Arun

1 Like

Hi @Arun-Kumar
Thanks, your code is working for other user field. But showing blank field when “My Self” radio button, which gives output in Field 20, is selected.

Hi @pctripathi,

i have verified, it is populating the managerName when you select the “My Self” radio button. Are you testing this form using spadmin? If the managerName is empty for the Identity, it will not populate the managerName. You can add the else condition like managerName is null, you can return the spadmin as a Manager. I have included that logic. Please check with this and let me know.

Regards,
Arun

Hi @Arun-Kumar
Thanks for your solution.
And if I need the supervisor details instead of manager’s details should I go ahead and replace .getManager with .getSupervisor?

I checked and found that in some accounts manager name is missing but supervisor name is given in every account. So I am thinking to user Supervisor instead of manager.

Tried .getSupervisor and .getSupervisorName but neither of them worked.

Hi @pctripathi,

getSupervisor() method is not available in Identity Object. You should use identity.getAttribute(“supervisor”) method to get the supervisor details. Please check what is the Identity attribute name for supervisor in identity Mapping.

Regards,
Arun

HI @Arun-Kumar
Can you share any template like where I can use Supervisor Name instead of Manager.
I checked in identities name of the supervisors is written under “Supervisor Name” type. And most of them manager name is null under “Manager” type.

Regards,
Pratik

Hi @pctripathi,

Go to Global settings–>Identity Mappings. Search the supervisor attribute and open. you can see the actual Attirbute name for the Supervisor. You should use the same attribute name in identity.getAttribute(“Attribute name”); Replace the Attribute name with supervisor attribute name. Attach the screen shot for reference.

1 Like

Hi @Arun-Kumar
Does this code looks good?

@pctripathi,

updated the code

1 Like

Hi @Arun-Kumar
Thanks for the solution. It is working now.
Small concern though. Even after enebling refresh on change, when I am coming back to “My Self radio button”, the manager is not changing. Infact, MySelf manager name is visible before selecting mySelf button with opening of the form.

Hi @pctripathi,

please refer the below link.
form field clear

1 Like