Sample onValidate inline script

This topic has 2 replies, 3 voices, and was last updated 6 days, 2 hours ago by Andrew Potter.

  • Author
    Posts
  • #28355
     rneucom
    Participant

    Does anyone have a sample inline script for the onValidate event of a managed user attribute? A pointer to some docs on it would be a great alternative. I cannot find any docs on what is passed/returned and how to create meaningful error messages from the (in-line) script.

    thanks
    Raymond

    #28358
     Jatinder Singh
    Participant

    The default inline scripts available for other events use require to load appropriate JS files and invoke available functions e.g. require('onUpdateUser').preserveLastSync(object, oldObject, request);. The onUpdateUser script in this example resides under the default “script” folder.

    Depending upon your use case, you could follow similar suit. And in terms of what objects are available, please check the below link:

    https://backstage.forgerock.com/docs/idm/7/scripting-guide/script-triggers-managed.json.html

    #28370
     Andrew Potter
    Participant

    As per the link Jatinder gave, the onValidate hook should return a ‘JSON object’. This represents the value of the thing you want to store. So, assuming this is the onValidate script for an object, the onValidate script should return the full JSON object of the object.
    i.e. something along the lines of

    logger.debug("onValidate: " + object);
    object.fullName=object.givenName + ' ' + object.sn;
    object;

    To throw error messages, the technique described for ‘custom endpoints’ here works: https://backstage.forgerock.com/knowledge/kb/article/a83104297
    e.g.

    logger.debug("onValidate: " + object);
    if (object.givenName !=null) {
      object.fullName=object.givenName + ' ' + object.sn;
      object;
    } else {
      throw {
        "code": 500, // any valid HTTP error code
        "message": "Given Name must be supplied",
        "reason": "blah blah",
            "detail": {
            "code": "ERROR1",
            "severity": "Fatal",
            "description": "We must have a given name"
        }
      }
    }
    
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

©2020 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?