pctripathi
(Pratik Chandra Tripathi)
July 25, 2024, 7:27am
1
In the above image i am trying to get different values in the field based on the radio button selected. When I click on Myself it shows my own detail in the field. I want to write a script for the “Other User” radio button so that when I select that the field changes to a dropdown field and lists all the accounts available in my sailpoint and also I should be able to search in it since scrolling through accounts may not be easy. The code that I have written till now is also given below. Please help me in this.
<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">
<Script>
<Source>
import sailpoint.object.*;
Field f1 = form.getField("Field 1");
if(f1!=null){
String selected = f1.getValue();
log.error(selected);
if (selected!=null && selected.equalsIgnoreCase("Myself")){
return context.getUserName();
}
}
return "";
</Source>
</Script>
</Field>
</Section>
Hi @pctripathi ,
I see 2 way. In if case for “other user” you can use a dynamicValue for change how filed contains, something like this:
DynamicValue dynamicValue = new DynamicValue();
dynamicValue.setValue(list);
f1.setAllowedValuesDefinition(dynamicValue);
or you can create 2 different field and hide/show respect of the value is selected on radiobutton
1 Like
pctripathi
(Pratik Chandra Tripathi)
July 25, 2024, 8:03am
3
Hi @enistri_devo
Is there any way I can get to show the accounts in the sailpoint in realtime to relfect in my dropdown list.
I never try with account, but you can read the account and return a list of them
Sriindugula
(Sri Veera Siva Kumar Indugula)
July 25, 2024, 8:33am
5
Hi @pctripathi
You can try something like below (not tested just sample ) code:
<Field displayName="Accounts" dynamic="true" name="IdentityLinks" postBack="true" required="true" type="Link">
<Script>
<Source>
import sailpoint.object.*;
Field f1 = form.getField("Field 20");
if(f1!=null){
String selected = f1.getValue();
log.error(selected);
if (selected!=null){
Identity idn = context.getObjectByID(Identity.class,selected);
if(idn!=null){
return idn.getLinks();
}
}
}
return "";
</Source>
</Script>
</Field>
Hope this helps!
Thanks
2 Likes
Hi @pctripathi ,
I have worked with something in the past, where based on a value that was selected/inputted in the field we hid/showed another input field.
<Field columnSpan="1" displayName="Company" dynamic="true" name="options" postBack="true" type="string">
<AllowedValuesDefinition>
<Value>
<List>
<String>Myself</String>
<String>Other User</String>
</List>
</Value>
</AllowedValuesDefinition>
</Field>
<Field columnSpan="1" displayName="Other Vendor" name="allAccounts" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden" value="rule:{{YOUR RULE NAME}}"/>
</Map>
</Attributes>
<script>
<!-- Getting all the accounts -->
</script>
</Field>
<Field columnSpan="1" displayName="Other Vendor" name="myAccount" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden" value="rule:{{YOUR RULE NAME}}"/>
</Map>
</Attributes>
<script>
<!-- Getting one account -->
</script>
</Field>
This code isn’t tested but I just mocked this up now. What it will do is show/hide an input field based on the option you selected. The “Rule” value is intended so that you could perhaps do a form.get("options").getValue();
to check the value that the user selected and show the form option there after.
Thanks,
2 Likes
vedeepak
(Deepak Vema)
July 25, 2024, 10:26am
7
You can try something like below. I have tested and working for me
<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" readOnly="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 && 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 && correlated == true && email.notNull()) || workgroup == true" helpKey="Select one or more" multi="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 && 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>
2 Likes
pctripathi
(Pratik Chandra Tripathi)
July 25, 2024, 10:46am
8
Hi @vedeepak
Thanks Alot. That was a big help.
2 Likes
system
(system)
Closed
September 23, 2024, 2:27pm
10
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.