Form > Field > Attribute > Map > entry > value > Script does not support Includes?

					<Field name="retain_access" displayName="Access Rights" displayOnly="true" readOnly="true" dynamic="true" type="string" displayType="textarea" columnSpan="2">
						<Attributes>
							<Map>
								<entry key="height" value="200"/>
							</Map>
						</Attributes>
						<Script>
							<Includes><Reference class="sailpoint.object.Rule" name="RetainAccountRuleLibrary"/></Includes>
							<Source>return getIdentityAccess(retainUserId);</Source>
						</Script>
					</Field>
				</Section>
				<Section name="Step2" label="Retain Options" columns="2">
					<Field name="terminationDate" displayName="Termination Date" type="date"/>
					<Field name="rejoinDate" displayName="Rejoin Date" type="date"/>
					<Field name="keepEmail" displayName="Keep Email Active" type="boolean"/>
					<Field name="keepAccount" displayName="Keep Account Access" type="boolean"/> 
					<Field name="restoreToSameUser" displayName="Restore to Same User" type="boolean" postBack="true">
						<DefaultValue><Boolean>false</Boolean></DefaultValue>
					</Field>
					<Field name="restoreUserID" displayName="Restore to User" type="sailpoint.object.Identity" filterString="workgroup == false" dynamic="true" postBack="true" columnSpan="2">
						<Attributes><Map>
							<entry key="hidden"><value><Script>
								<Includes><Reference class="sailpoint.object.Rule" name="RetainAccountRuleLibrary"/></Includes>
								<Source>return getIdentityAccess(retainUserId);</Source>
							</Script></value></entry>
						</Map></Attributes>
					</Field>

The first call to the JS function getIdentityAccess() in Field > Script > Source works.
The second call in Field > Attributes > Map > entry > value > Script > Source doesn’t. It throws “Command Not Found” error.

How can I achieve code reuse in field attributes?

Both the “Field > Scripts” and “Field > Attribute > entry > Scripts” have access to the entire Form via a variable called “form”. Therefore they have access to any other Field in the Form. You can declare a hidden Field and initialize its value with some common value that you intend to reuse, and get that value in any block:

Object val = form.getField(“myHiddenField”).getValue();

But if I need to get form field as a boolean, I will need to do something like this:

Field f = form.getField("booleanField1");
if (f != null) {
    Object o = f.getValue();
    if (o != null) {
        return (Boolean) o;
    }
}
return defaultValue;

I’d rather have that in a rule library and reference it, than copy-pasting a blob of code everywhere.

e.g. I have a checkbox that will decide if 50 other fields is displayed or not. Think of amount of code to calculate the hidden attribute of these 50 other fields.

I’d want their hidden attribute to be:

<Attribute><entry><Script><Source>return isHidden(defaultValue);</Source></Script></entry></Attribute>

Have you tried just defining the reference at the top Workflow level?

<RuleLibraries>
  <Reference class="sailpoint.object.Rule" name="xyz"/>
</RuleLibraries>

I’m not 100% sure if that will work, but worth a try. I understand your pain though when it comes to complex Forms. What I typically do for this, and it may be a workaround if you cannot get the Script includes to work, is to use a rule with the following syntax:

<Field columnSpan="1" displayName="Category" displayType="combobox" helpKey="Categorization used for searchibility and naming guidelines" name="category" postBack="true" type="String">
  <Attributes>
    <Map>
      <entry key="readOnly" value="rule:SN-Rule-FieldReadOnly-EntitlementManagement"/>
      <entry key="hidden" value="rule:SN-Rule-FieldHidden-EntitlementManagement"/>
    </Map>
  </Attributes>
  <AllowedValuesDefinition>
    <RuleRef>
      <Reference class="sailpoint.object.Rule" name="SN-Rule-AllowedValues-EntitlementManagement"/>
    </RuleRef>
  </AllowedValuesDefinition>
</Field>

Workflow objects can become huge with scripts, allowed value lists, etc. so I typically just throw these rules on every Field and then have a Custom object that holds particular settings on how the Form should function.

I already have RuleLibrary defined at Workflow level, that’s how Field > Script > Source can use my JS functions.

The rule workaround involves managing a bunch of additional rules, but at least the rules can refer to the same RuleLibrary, and the form can be tidier.

Thanks!