Which IIQ version are you inquiring about?
Unsure
Share all details related to your problem, including any error messages you may have received.
I have a form and I’m trying to hide fields based on answers to previous forms. I’m trying to use form.getField().getValue() but I’m getting an error when I try to fill out the form. Here is the code I’m trying to use:
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import java.util.*;
import sailpoint.object.*;
import sailpoint.api.*;
String fieldValue = form.getField("FieldName").getValue();
try {
if (Util.isNotNullOrEmpty(fieldValue)) {
if(fieldValue.equals("FieldValue")) {
return false;
} else {
return true;
}
}
} catch (GeneralException e) {
e.printStackTrace;
}</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
This is the error that I’m getting:
Uncaught JAX-RS exception.
sailpoint.tools.GeneralException: sailpoint.tools.GeneralException: The application script threw an exception: java.lang.NullPointerException: Attempt to invoke method getValue on null value BSF info: script
How can I update this to use form.getField().getValue() correctly? Is there something else I should use to pull in the result of a previous field in this form?
kjakubiak
(Kamil Jakubiak)
April 25, 2024, 6:38pm
2
Usually you can reference field within the same form directly.
It would be good if you could paste whole form xml that would simplify troubleshooting.
MVKR7T
(Krishna Mummadi)
April 25, 2024, 7:22pm
3
Did you add postback and dynamic attributes for your field.
Thank you for your response. Here’s a sample of what I’m trying to do. In this example the field I’m trying to hide would be lastname based on the contents of FirstName:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Form PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Form created="1710449553878" id="0a5800038dd61680818e3ebcf1d6246a" modified="1714069640337" name="Form Name" type="Application">
<Attributes>
<Map>
<entry key="includeHiddenFields" value="true"/>
<entry key="isWizard" value="true"/>
<entry key="pageTitle" value="Form Name"/>
</Map>
</Attributes>
<Description>Note to user</Description>
<Section label="Sample Label" name="sampleLable">
<Attributes>
<Map>
<entry key="subtitle" value="subtitle"/>
</Map>
</Attributes>
</Section>
<Section columns="3" label="Section 1- Contact info" name="sectionOne">
<Field columnSpan="1" displayName="First Name" dynamic="true" name="FirstName" postBack="true" required="true" reviewRequired="true" type="string">
<Script>
<Source>import sailpoint.object.*;
String first = identity.getFirstname();
return first;</Source>
</Script>
</Field>
<Field columnSpan="1" dependencies="FirstName" displayName="Last Name" name="lastname" postBack="true" required="true" reviewRequired="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import java.util.*;
import sailpoint.object.*;
import sailpoint.api.*;
String fieldValue = form.getField("FirstName").getValue();
try {
if (Util.isNotNullOrEmpty(fieldValue)) {
if(fieldValue.equals("FieldValue")) {
return false;
} else {
return true;
}
}
} catch (GeneralException e) {
e.printStackTrace;
}</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
<Script>
<Source>import sailpoint.object.*;
String last = identity.getLastname();
return last;</Source>
</Script>
</Field>
</Section>
</Form>
Yes I’ve tried adding and removing both of these options and I get the same error.
check below sample code
<Field defaultValue="level5" displayName="Access Request - Approval Level" displayType="combobox" helpKey="Please select the appropriate approval level" name="approvalLevel" postBack="true" type="string">
<AllowedValues>
<String>level1</String>
<String>level4</String>
<String>level5</String>
</AllowedValues>
</Field>
<Field columnSpan="2" displayName="Name of Entitlement Owner Approvers" dynamic="true" multi="true" name="groupOwner" type="identity">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>
if(approvalLevel != null){
String levelOfAppr=(String) approvalLevel;
if(levelOfAppr.equals("level5")|| levelOfAppr.equals("level4))
{
return false;
}else{
return true;
}
}else{
return true;
}
</Source>
</Script>
</value>
</entry>
<entry key="readOnly" value="true"/>
</Map>
</Attributes>
</Field>
https://community.sailpoint.com/t5/IdentityIQ-Forum/How-to-hide-a-Field-in-form-based-on-the-value-of-another-Field/m-p/228337
kjakubiak
(Kamil Jakubiak)
April 25, 2024, 8:23pm
7
I think I solved your problem - as Vishal mentioned in his code and as I said on the beggining you don’t have to use form.getField()
- you can just use reference directly - like here
<Field name="FirstField" postBack="true" reviewRequired="true" type="string"/>
<Field dependencies="FirstField" dynamic="true" name="HiddenField" reviewRequired="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>if("hide".equals(FirstField)){
return true;
}else{
return false;
}</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
</Field>
I’ve added reviewRequired here as I see you use this form in provisioning policy that means if the field is not required it will not show up in the form if no rewievRequired is set to true.
In your code it would be something like that
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Form PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Form created="1710449553878" id="0a5800038dd61680818e3ebcf1d6246a" modified="1714069640337" name="Form Name" type="Application">
<Attributes>
<Map>
<entry key="includeHiddenFields" value="true"/>
<entry key="isWizard" value="true"/>
<entry key="pageTitle" value="Form Name"/>
</Map>
</Attributes>
<Description>Note to user</Description>
<Section label="Sample Label" name="sampleLable">
<Attributes>
<Map>
<entry key="subtitle" value="subtitle"/>
</Map>
</Attributes>
</Section>
<Section columns="3" label="Section 1- Contact info" name="sectionOne">
<Field columnSpan="1" displayName="First Name" name="FirstName" postBack="true" required="true" reviewRequired="true" type="string">
<Script>
<Source>import sailpoint.object.*;
String first = identity.getFirstname();
return first;</Source>
</Script>
</Field>
<Field columnSpan="1" dependencies="FirstName" displayName="Last Name" name="lastname" required="true" reviewRequired="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>import java.util.*;
import sailpoint.object.*;
import sailpoint.api.*;
String fieldValue = FirstName;
try {
if (Util.isNotNullOrEmpty(fieldValue)) {
if(fieldValue.equals("FieldValue")) {
return false;
} else {
return true;
}
}
} catch (GeneralException e) {
e.printStackTrace;
}</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
<Script>
<Source>import sailpoint.object.*;
String last = identity.getLastname();
return last;</Source>
</Script>
</Field>
</Section>
</Form>
1 Like
When I try this logic, I get an error:
Uncaught JAX_RS exception
sailpoint.tools.GeneralException: Attempt to resolve method: isNotNullOrEmpty() on undefined variable or class name: Util : at Line: 7
kjakubiak
(Kamil Jakubiak)
April 25, 2024, 8:40pm
9
You forgot to import Util class
(Util.isNotNullOrEmpty(fieldValue))
Perfect, that fixed it! Thanks!
system
(system)
Closed
June 24, 2024, 8:44pm
11
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.