Sample onValidate inline script

This topic has 4 replies, 4 voices, and was last updated 8 months, 2 weeks ago by Andrew Potter.

  • Author
  • #28355

    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.


     Jatinder Singh

    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:

     Andrew Potter

    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 + ' ' +;

    To throw error messages, the technique described for ‘custom endpoints’ here works:

    logger.debug("onValidate: " + object);
    if (object.givenName !=null) {
      object.fullName=object.givenName + ' ' +;
    } 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"

    Hi @andrew-potter here is my custom error msg

    var message = 'Resource passwordPolicy' + ' ' + passwordPolicy + ' does not exist.';
            var messages = { code: 400, message: message, detail: []};
            var err = {
                severity: 'error',
                code: 'NOT_EXIST',
                details: message
    throw messages;

    But actually in Postman idm return 500

        "code": 500,
        "reason": "Internal Server Error",
        "message": "passwordPolicy onStore script encountered exception"
     Andrew Potter

    Take a look at this and follow the approach for the scripting language you’re using:
    I think the issue is that detail should be an object, not an array.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

©2022 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?