Scripted Decision StringAttributeInputCallback

Hello

I need to write a custom progressive profile form (mainly layout, options, etc) so need to write a custom decision node. Was going to use the StringAttributeInputCallback rather than the text input if possible but not seeing many (if any) javascript examples. Does anyone have an example of one really quick they might be able to share that i can use?

https://backstage.forgerock.com/docs/idcloud/latest/am-authentication/authn-interactive-callbacks.html#StringAttributeInputCallback

Thanks
Nick

In Scripted decision node API :: AM 7.5.0 : → callbacksBuilder request methods =>

  • public void stringAttributeInputCallback(String name, String prompt, String value, Boolean required)
  • public void stringAttributeInputCallback(String name, String prompt, String value, Boolean required, List<String> failedPolicies)
  • public void stringAttributeInputCallback(String name, String prompt, String value, Boolean required, Object policies, Boolean validateOnly)
  • public void stringAttributeInputCallback(String name, String prompt, String value, Boolean required, Object policies, Boolean validateOnly, List<String> failedPolicies)

callbacks public get methods => =>

getStringAttributeInputCallbacks() List<String> The collected String value

That same document page has examples that shows how to handle callbacks, just adapt with the specific stringAttributeInputCallback methods…

hey are you able to figure this out? kindly share the sample script

Here’s an example of how I have used it before

if(callbacks.isEmpty()){
    callbacksBuilder.stringAttributeInputCallback("attrib","Enter your attribute",null,true,null,false)
} else {
    logger.error(callbacks);
    input = callbacks.getStringAttributeInputCallbacks().get(0);
	outcome = "true";
}

If you want to send the data for Policies or Failed Policies instead of null, you can use the below functions. I’ve written the functions in such a way that it maintains the structure of policies and failed policies sent by out of the box node Attribute Collector.

function getPoliciesForAProperty(property, managedObjectContainer) {


	// Call to IDM to get policy details for all properties of giveb managed object
	var response = openidm.read("policy/" + managedObjectContainer + "/*");
	
	
	var properties = response? response.get("properties"): null;
	
	if(!properties || !properties.length){
		return false
	}
	
	for (var i = 0; i<properties.length; i++){
		if (properties[i].name === property){
			return { "policyRequirements" : properties[i].policyRequirements,
                     "name": properties[i].name,
                     "policies" : properties[i].policies,                     
                     "conditionalPolicies" : properties[i].conditionalPolicies,
                     "fallbackPolicies" : properties[i].fallbackPolicies                    
					}
		}	
	}
  return false
}


function validateProperty(propertyMap, managedObjectContainer, managedObject) {

	
	var response = openidm.action("policy/" + managedObjectContainer + "/" + managedObject, "validateProperty", propertyMap);
	
	var policyValidationStatus = response? response.get("result"): true;
	
	if(policyValidationStatus){
		return null
	}else {
		var failedPoliciesArray = []
		var failedPolicyRequirements = response.get("failedPolicyRequirements")
		for (var i = 0; i < failedPolicyRequirements.length; i++){
			failedPoliciesArray[i] =  failedPolicyRequirements[i].policyRequirements.toString().slice(1,-1)
		}
		return failedPoliciesArray
	}
}

Reference for failed policy validation: Manage policies over REST :: IDM 7.4.1 (forgerock.com)

1 Like