Monday, December 10, 2012

Quick tips for a successful deployment & user adoption: duplicate the dashboards


Introduction

User adoption is the key to a successful CRM project. Sugar will help you to accomplish this goal: Sugar flexibility and intuitiveness will let the end user feel like home. He may set up his CRM to look the way he wants: setting his home page drag & dropping dashlets, adding graphic reports, adding tabs has never been so easy.

But if you are working on a big deployment, you need to automatize tasks. However, some of them are not (yet) available out of the box in Sugar (and will never exist in Salesforce, he he): set the user password to a value and duplicate the dashboards. Both will be done programmatically. This is straightforward, no sweat.

Why setting a password? 
Sugar can generate a temporary password. The idea behind this is to leverage user adoption by setting human readable password that you will choose. Or it could for any other reasons:  e.g. setting the same password in different systems (you should then better consider Single Sign-On), setting an initial password that will be compliant with your corporate password rules.

Why setting dashboards?
For example you are launching a new CRM system for a call center and you want all the Support Reps to start with the same dashboard. And you might want to choose to freeze the dashboards and prevent the users from modifying them.

Assumption
You can access to your database with a client (gui or the command line).


Setting the password
The password is stored as a hash value in the database. The function that is calculating it is located on the User object. I highly recommended you to use the Sugar framework in order to stay upgrade safe.

Write a PHP file starting from the example below, save it to your Sugar instance root directory, log in the instance and execute the PHP file with your browser.


<html>
<head></head>
<body>
<?php
include ('include/MVC/preDispatch.php');
$startTime microtime(true);
require_once(
'include/entryPoint.php');
ob_start();
require_once(
'include/MVC/SugarApplication.php');
$app = new SugarApplication();
$app->startSession();

$u = new User();
$u->retrieve('seed_sally_id');
$u->user_hash User::getPasswordHash('sally');
$u->save();

echo 
"Password changed for Sally!";
?>
</body>
</html>


Alternative solution
Since you got the hash value using PHP, you may shoot a sql query:
update users
set user_hash='$1$rINuoIur$DhLu0b2AUgjrll7jX5bPP.' 
where user_name='sally';


Duplicate the dashboards
The dashboards user preferences are stored in the database, table user_preferences.
Before making changes, let's do a quick backup:
mysqldump --add-drop-database -u userdb -p'password' dbinstancename user_preferences > user_preferences-backup.sql

Then, create a new user, give him the expected role and set his dashboard. You might want to copy the preferences from an existing user, but this user should not use Sugar during the copy process.
When duplicating the user preferences, you will copy all the customizations: dashboards, list views, sub panels orders, etc.

Duplicating his preferences is easy, just 1 sql line:
insert into user_preferences(id,assigned_user_id,contents,category) 
select UUID(),'target user id',contents,category from user_preferences where assigned_user_id='source user id';

When duplicating the user preferences, you will copy all the customizations: dashboards, list views, sub panels orders, etc. To reduce the scope, add a "where clause":
insert into user_preferences(id,assigned_user_id,contents,category) 
select UUID(),'target user id',contents,category 
from user_preferences 
where assigned_user_id='source user id' and category like 'Home%';

A best practice would be to set the dashboard on a user and copy his preferences to a dedicated table. Let's create this table from the user_preferences:
CREATE TABLE `user_preferences_cp` (
  `id` char(36) NOT NULL,
  `category` varchar(50) DEFAULT NULL,
  `deleted` tinyint(1) DEFAULT '0',
  `date_entered` datetime DEFAULT NULL,
  `date_modified` datetime DEFAULT NULL,
  `assigned_user_id` char(36) DEFAULT NULL,
  `contents` longtext,
  PRIMARY KEY (`id`),
  KEY `idx_userprefnamecat_cp` (`assigned_user_id`,`category`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Copy the preferences to this table:
insert into user_preferences_cp(id,assigned_user_id,contents,category) 
select UUID(),'source user id',contents,category from user_preferences where assigned_user_id='source user id';

Then, when duplicating, use the new table:
insert into user_preferences(id,assigned_user_id,contents,category) 
select UUID(),'target user id',contents,category from user_preferences_cp where assigned_user_id='source user id';

Enjoy your new dashboards :-)

No comments:

Post a Comment