Send email to Manager on new User Creation

This topic has 6 replies, 4 voices, and was last updated 2 years, 7 months ago by jelikapahwa.

  • Author
    Posts
  • #19832
     Dhakad
    Participant

    Hi,

    I am working on a test scenario and want to send a email on user creation to his manager. To configure this create a new “triggerEmailNotification.js” and calling it in the managed.json as per the below format. After this configuration able to send mail tp “object.mail” but not able to send mail to manager. Please suggest way to achieve this
    ————————————–managed.json——————————————————————————
    “PostCreate” : {
    “type” : “text/javascript”,
    “file” : “ui/triggerEmailNotification.js”
    }
    —————————————triggerEmailNotification.js———————————————–This is the function write to sent email to manager (Working if use to”: object.mail,)

    function sendVerificationEmail()
    {
    var emailConfig = openidm.read(“config/external.email”);

    var obj=openidm.read(‘managed/user/manager’);

    if(emailConfig){
    var email = {
    “from”: emailConfig.from,
    “to”: obj.mail,
    “subject”: “Verification Email”,
    “type”: “text/html”,
    “body”:”test”
    };
    openidm.action(“external/email”, “sendEmail”, email);
    }

    };

    Thanks,
    Bherulala Dhakad

    #19833
     Dhakad
    Participant

    ———————————error logs for the above topic——————————————-org.forgerock.openidm.servlet.internal.ServletConnectionFactory$3 handleException
    WARNING: Resource exception: 500 Internal Server Error: “postCreate script encountered exception”
    org.forgerock.json.resource.InternalServerErrorException: postCreate script encountered exception
    Caused by: org.mozilla.javascript.EcmaError: TypeError: Cannot read property “mail” from null

    #19845
     Jake Feasel
    Moderator

    var obj=openidm.read('managed/user/manager'); is returning null, this is why you are getting the error. You need to change this to read from the “/manager” endpoint under the particular managed/user you are working with, like so:

    var obj=openidm.read('managed/user/'+object._id+'/manager', null, ['*']);

    The last parameter is the “fields” – you need to specify that you want to expand the relationship to the manager in order to get the email details.

    • This reply was modified 3 years, 2 months ago by Jake Feasel.
    #19847
     Dhakad
    Participant

    Hi,
    Now am getting null point exception error. Error logs are

    Dec 01, 2017 4:15:12 PM org.forgerock.openidm.servlet.internal.ServletConnectionFactory$3 handleException
    WARNING: Resource exception: 500 Internal Server Error: “postCreate script encountered exception”
    org.forgerock.json.resource.InternalServerErrorException: postCreate script encountered exception
    at org.forgerock.json.resource.ResourceException.newResourceException(ResourceException.java:231)
    at org.forgerock.script.exception.ScriptThrownException.toResourceException(ScriptThrownException.java:115)
    Caused by: org.forgerock.script.exception.ScriptThrownException: Wrapped java.lang.NoSuchMethodException: Method not found warn(null) java.lang.NoSuchMethodException: Method not found warn(null)
    at org.forgerock.script.javascript.RhinoScriptEngine$3.newScriptThrownException(RhinoScriptEngine.java:406)
    at org.forgerock.script.javascript.RhinoScript.eval(RhinoScript.java:298)
    at sun.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
    Caused by: java.lang.NoSuchMethodException: Method not found warn(null)
    at org.forgerock.script.scope.FunctionFactory$1$2.call(FunctionFactory.java:92)
    at org.forgerock.script.scope.FunctionFactory$1$2.call(FunctionFactory.java:81)
    at org.mozilla.javascript.gen.file__app_openidm_bin_defaults_script_ui_triggerEmailNotification_js_250._c_anonymous_1(file:/app/openidm/bin/defaults/script/ui/triggerEmailNotification.js:10)
    at org.mozilla.javascript.gen.file__app_openidm_bin_defaults_script_ui_triggerEmailNotification_js_250.call(file:/app/openidm/bin/defaults/script/ui/triggerEmailNotification.js)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)

    Thanks,
    Bherulal Dhakad

    #19926

    given the trace, you probably try to do some logging in triggerEmailNotification line 10. It has to be “logger.warn” in javascript, groovy would use log.warn.

    #20013
     Dhakad
    Participant

    Thanks for your support.

    Working now. Split the read operation.
    1) Read the User ID “._id”
    2) Read the Manager “._ref”

    Regards,
    Bherulal Dhakad

    #22549
     jelikapahwa
    Participant

    @dhakad -Could you please share the working transformation script , Actually i am provisioning manager attribute to CSV but its returning null .I am using “openidm.read(source._ref).username” in Transformation script.

    Appreciate if you could help .

    Thank You

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

You must be logged in to reply to this topic.

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