The CreatorCon Call for Content is officially open! Get started here.

How can I automatically set a password for Contact X when a user with role: sn_customerservice.customer_admin self-created Contact X using the item "Create Contact"?

Haruka Kubota1
Tera Contributor

How can I automatically set a password for Contact X when a user with role: sn_customerservice.customer_admin self-created Contact X using the item "Create Contact"?

I have successfully set up user ID automatically in FlowDesigner, but I cannot set up a password.

We would like to complete the creation of contacts only by the customer, without the system administrator (admin, etc.) intervening in the creation of contacts.

I would appreciate if someone could give me some advice.

Thanks,
Haruka Kubota

1 ACCEPTED SOLUTION

Hi @Haruka Kubota 

Sure, will assist you here. 

Password field which we are trying to set here is a field of dictionary type = password which once set cannot be decrypted and you cannot see the value once it is set.

So please do not get confused with SetDisplayValue being used, it will not show. IF that is giving you an error then please modify your script as below:

(function executeRule(current, previous /*null when async*/ ) {

    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';

    for (var i = 0; i < string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);

        randomstring += chars.substring(rnum, rnum + 1);
    }

    //Generate Notification
    gs.eventQueue("user.password", current, randomstring, current.email);
    //Set values in User record
    current.user_password = randomstring;
    current.password_needs_reset = true;
    current.update();
})(current, previous);

This Script should work fine now without any issues for you.

Second query:

In the script above, if you see there is a line written with syntax as below:

gs.eventQueue("user.password", current, randomstring, current.email);

So user.password is a Event which you need to configure first, please follow the steps through which you can configure this:

1) Navigate to the module "Registry" and create a event named "user.password" as shown below:

find_real_file.png

Now if you need to send this password to someone then we are passing the password as one of the event parameter, so you can access that in a Notification email script which can then be used in a Notification as per steps below:

Navigate to the module "Notification Email Script" and use the script as below which will allow you to send the password generated to the email which is also a parameter being passed from your Business Rule above:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here
	var par1 = event.parm1.toString();
	template.print('Password is ' + par1);

})(current, template, email, email_action, event);

find_real_file.png

Final Step:

Configure your Notification:

Notification should be on the same table as your Business Rule

Trigger Condition will be Event Based and select the event name configured in steps above.

Make sure to select below 3 parameter:

Parm 1

Parm 2

Send to Event Creator

You can call the Notification email script in your Notification using the syntax below:

${mail_script:Mail Script Name}

Adding the screenshot as well for your reference on how you are going to create your Notification as well to avoid any confusion:

find_real_file.png

find_real_file.png

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

6 REPLIES 6

Thank you very much for your kindness.

I was able to solve the problem using the method you taught me. It helped me a lot!

is this still valid using the customer contact table? I was getting some duplicate entry errors.