- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2022 03:24 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 03:44 AM
Hi
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:
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);
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:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2022 04:04 AM
Hi
Please find the steps below to achieve your requirement:
1) Create a Business Rule on Contact table where you are creating Contact records
BR Details:
Table Name: Select your Table
When: Before Insert
Script:
(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.setDisplayValue(randomstring);
current.password_needs_reset = true;
current.update();
})(current, previous);
You can trigger the Notification and send the user's email and password in the parameters.
Note: You can even reuse the same code for reset the password.
You can modify the above code if you need as per your requirement.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2022 09:01 PM
Hi
Thanks to you I was able to set a random password!
Let me ask you an additional question.
<Question>
Thanks for letting me know that I can trigger the notification and send user's password in the parameters.
How do I set up the trigger for this notification? I've tried, but it's not working...
If you have a solution, please let me know.
Thanks,
Haruka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2022 09:19 PM
Hi
Thanks to you I was able to set a random password!
I was able to set a random password, but I have two new problems.
Let me ask you two additional questions.
1. "current.user_password.setDisplayValue(randomstring);" does not seem to be working correctly.
The next line "current.password_needs_reset = true;" is confirmed to work correctly.
If you can think of any other way to describe this, please let me know.
It seems that the following error was occurring.
2. Thanks for letting me know that I can use the notification triggers to send password in the parameters.
How do I set up this notification trigger? I've tried, but it doesn't work... (not triggered)
Please let me know if you know of solutions.
Thanks,
Haruka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 03:44 AM
Hi
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:
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);
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:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke