For Zoho Services only:


I'm actually part of something bigger at Ascent Business Solutions recognized as the top Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions offer support for smaller technical fixes and projects for larger developments, such as migrating to a ZohoCRM.  A team rather than a one-man-band is always available to ensure seamless progress and address any concerns. You'll find our competitive support rates with flexible, no-expiration bundles at http://ascentbusiness.co.uk/zoho-support-2.  For larger projects, check our bespoke pricing structure and receive dedicated support from our hands-on project consultants and developers at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices.

The team I manage specializes in coding API integrations between Zoho and third-party finance/commerce suites such as Xero, Shopify, WooCommerce, and eBay; to name but a few.  Our passion lies in creating innovative solutions where others have fallen short as well as working with new businesses, new sectors, and new ideas.  Our success is measured by the growth and ROI we deliver for clients, such as transforming a garden shed hobby into a 250k monthly turnover operation or generating a +60% return in just three days after launch through online payments and a streamlined e-commerce solution, replacing a paper-based system.

If you're looking for a partner who can help you drive growth and success, we'd love to work with you.  You can reach out to us on 0121 392 8140 (UK) or info@ascentbusiness.co.uk.  You can also visit our website at http://ascentbusiness.co.uk.

ZohoCRM & ZohoWriter: Generate Rich-Text / HTML Email Signatures in CRM

What?
This is an article to show you how to, using Deluge code, generate all the email signatures in the user profile in ZohoCRM.

Why?
To simplify the on-boarding process. A client of ours has a rather rich HTML email signature with a profile photo included. When sending an email from CRM, they want CRM to include this rich signature (different per user) at the bottom of the email message.

How?
So there are a few issues with displaying images which would have other solutions, such as hosting the images on a web-server, or converting to a base64 or an SVG. ZohoCRM signatures seem to be unable to handle a lot of code or long URLs such as a base64 source URL for an image.

The Plan
  1. Get company phone and website from Organization Details in ZohoCRM.
  2. Upload and get publicly-accessible image URL to/from ZohoWriter.
  3. Loop through active users in ZohoCRM.
  4. Merge the HTML email signature with the fields evaluated.

Function: fn_Workdrive_HostImage
I add this function to the CRM and use it as a standalone function to upload generic images (such as facebook, instagram, icons, and partner logos). This function is for images that will be on all signatures and don't have anything identifying per user. So this function uploads the image to the client's workdrive and you will need the long hash ID of the folder:
  1. Login as the client to ZohoWorkdrive (www.zoho.com/workdrive)
  2. Signin or Access
  3. You should be in "My Folders" (left sidebar)
  4. Create a folder, I'm calling mine "Email Signature Images"
  5. Within that folder, create another folder called "_Global".
  6. At the same level, create another folder called "Profile Photos".
  7. Navigate into the "_Global" folder and note the last hash in the URL (after "/folders/")
    Zoho Workdrive - Get Folder Hash ID
For this function, I have a connection called "zworkdrive" which has the scopes as specified in the function header. Also note, that this Zoho instance is in the EU datacenter (zoho.eu) rather than the US datacenter. The most important tweak in order for the below to work, is to add a file upload field on the user profile in ZohoCRM; Login as SuperAdmin > Users > Edit a User > Manage Fields > Drag a "File Upload" field and call it "Signature Image":
copyraw
/* *******************************************************************************
Function:       String fn_Workdrive_HostImage(string p_DownloadImageUrl, string p_WorkdriveFolder)
Label:          Fn - Workdrive - Host Image
Trigger:        Off a button / Standalone
Purpose:		This uploads an image to workdrive and returns a publicly-accessible link/URL for use in your email signatures.
Inputs:         Loginuser
Outputs:        Email
Scope(s):		WorkDrive.team.ALL, WorkDrive.workspace.ALL, WorkDrive.files.ALL, WorkDrive.organization.READ, WorkDrive.teamfolders.ALL, WorkDrive.links.ALL, WorkDrive.DataTemplates.READ

Date Created:   2023-12-05 (Joel Lipman)
                - Initial release
				- Uploads an image to workdrive and returns the public link
Date Modified:	???
                - ???
				
ttps://workdrive.zoho.com/apidocs/v1/filefoldersharing/shareeveryone			
******************************************************************************* */
//
// Go create a folder in workdrive, take the last hash string after the word /folders/ in the URL:
v_TargetFolder = ifnull(p_WorkdriveFolder,"abcdefghijklmnopqrstuvwxyz12345678901");
v_ImageToDownload = ifnull(p_DownloadImageUrl,"https://joellipman.com/tmp/icon_linkedin.jpg");
v_FileName = v_ImageToDownload.subString(v_ImageToDownload.lastIndexOf("/") + 1);
//
// get file object
f_File = invokeurl
[
	url :v_ImageToDownload
	type :GET
];
//
// upload file to workdrive
r_WorkdriveUpload = zoho.workdrive.uploadFile(f_File,v_TargetFolder,v_FileName,true,"zworkdrive");
info "Workdrive response:";
info r_WorkdriveUpload;
if(!isNull(r_WorkdriveUpload.get("data")))
{
	//
	// set permissions to public and visible
	m_Headers = Map();
	m_Headers.put("Accept","application/vnd.api+json");
	for each  r_Data in r_WorkdriveUpload.get("data")
	{
		r_Attributes = r_Data.get("attributes");
		v_ResourceID = r_Attributes.get("resource_id");
	}
	//
	// generate permissions to send to workdrive
	m_Attributes = Map();
	m_Attributes.put("resource_id",v_ResourceID);
	m_Attributes.put("shared_type","everyone");
	// 34 for files // 6 for folders
	m_Attributes.put("role_id","34");
	m_Data = Map();
	m_Data.put("attributes",m_Attributes);
	m_Data.put("type","permissions");
	m_Params = Map();
	m_Params.put("data",m_Data);
	r_Permissions = invokeurl
	[
		url :"https://www.zohoapis.eu/workdrive/api/v1/permissions"
		type :POST
		parameters:m_Params.toString()
		headers:m_Headers
		connection:"zworkdrive"
	];
	info "Workdrive Permissions:";
	info r_Permissions;
	//
	// response returns public permalink
	if(!isNull(r_Permissions.get("data")))
	{
		if(!isNull(r_Permissions.get("data").get("attributes")))
		{
			v_ImageURL = r_Permissions.get("data").get("attributes").get("permalink");
			v_ImageURL = v_ImageURL.replaceAll("https://workdrive.zohopublic.eu/file/","",true);
			//
			// replaced with URL taken on inspect element
			v_ImageURL = "https://previewengine-accl.zohopublic.eu/image/WD/" + v_ImageURL;
		}
	}
}
return v_ImageURL;
  1.  /* ******************************************************************************* 
  2.  Function:       string fn_Workdrive_HostImage(string p_DownloadImageUrl, string p_WorkdriveFolder) 
  3.  Label:          Fn - Workdrive - Host Image 
  4.  Trigger:        Off a button / Standalone 
  5.  Purpose:        This uploads an image to workdrive and returns a publicly-accessible link/URL for use in your email signatures. 
  6.  Inputs:         Loginuser 
  7.  Outputs:        Email 
  8.  Scope(s):        WorkDrive.team.ALL, WorkDrive.workspace.ALL, WorkDrive.files.ALL, WorkDrive.organization.READ, WorkDrive.teamfolders.ALL, WorkDrive.links.ALL, WorkDrive.DataTemplates.READ 
  9.   
  10.  Date Created:   2023-12-05 (Joel Lipman) 
  11.                  - Initial release 
  12.                  - Uploads an image to workdrive and returns the public link 
  13.  Date Modified:    ??? 
  14.                  - ??? 
  15.   
  16.  ttps://workdrive.zoho.com/apidocs/v1/filefoldersharing/shareeveryone 
  17.  ******************************************************************************* */ 
  18.  // 
  19.  // Go create a folder in workdrive, take the last hash string after the word /folders/ in the url: 
  20.  v_TargetFolder = ifnull(p_WorkdriveFolder,"abcdefghijklmnopqrstuvwxyz12345678901")
  21.  v_ImageToDownload = ifnull(p_DownloadImageUrl,"https://joellipman.com/tmp/icon_linkedin.jpg")
  22.  v_FileName = v_ImageToDownload.subString(v_ImageToDownload.lastIndexOf("/") + 1)
  23.  // 
  24.  // get file object 
  25.  f_File = invokeUrl 
  26.  [ 
  27.      url :v_ImageToDownload 
  28.      type :GET 
  29.  ]
  30.  // 
  31.  // upload file to workdrive 
  32.  r_WorkdriveUpload = zoho.workdrive.uploadFile(f_File,v_TargetFolder,v_FileName,true,"zworkdrive")
  33.  info "Workdrive response:"
  34.  info r_WorkdriveUpload; 
  35.  if(!isNull(r_WorkdriveUpload.get("data"))) 
  36.  { 
  37.      // 
  38.      // set permissions to public and visible 
  39.      m_Headers = Map()
  40.      m_Headers.put("Accept","application/vnd.api+json")
  41.      for each  r_Data in r_WorkdriveUpload.get("data") 
  42.      { 
  43.          r_Attributes = r_Data.get("attributes")
  44.          v_ResourceID = r_Attributes.get("resource_id")
  45.      } 
  46.      // 
  47.      // generate permissions to send to workdrive 
  48.      m_Attributes = Map()
  49.      m_Attributes.put("resource_id",v_ResourceID)
  50.      m_Attributes.put("shared_type","everyone")
  51.      // 34 for files // 6 for folders 
  52.      m_Attributes.put("role_id","34")
  53.      m_Data = Map()
  54.      m_Data.put("attributes",m_Attributes)
  55.      m_Data.put("type","permissions")
  56.      m_Params = Map()
  57.      m_Params.put("data",m_Data)
  58.      r_Permissions = invokeUrl 
  59.      [ 
  60.          url :"https://www.zohoapis.eu/workdrive/api/v1/permissions" 
  61.          type :POST 
  62.          parameters:m_Params.toString() 
  63.          headers:m_Headers 
  64.          connection:"zworkdrive" 
  65.      ]
  66.      info "Workdrive Permissions:"
  67.      info r_Permissions; 
  68.      // 
  69.      // response returns public permalink 
  70.      if(!isNull(r_Permissions.get("data"))) 
  71.      { 
  72.          if(!isNull(r_Permissions.get("data").get("attributes"))) 
  73.          { 
  74.              v_ImageURL = r_Permissions.get("data").get("attributes").get("permalink")
  75.              v_ImageURL = v_ImageURL.replaceAll("https://workdrive.zohopublic.eu/file/","",true)
  76.              // 
  77.              // replaced with URL taken on inspect element 
  78.              v_ImageURL = "https://previewengine-accl.zohopublic.eu/image/WD/" + v_ImageURL; 
  79.          } 
  80.      } 
  81.  } 
  82.  return v_ImageURL; 

Function: fn_Settings_EmailSignatures
Important: the following code will overwrite ALL signatures in the CRM. The email signature it will overwrite is the one held in ZohoCRM > Setup > Channels > Email > Email Configuration > Compose > Email Signature as in the following screenshot:
Zoho CRM - Setup / Configuration - Email Signature
This function generates all email signatures (no criteria). You will need to change the HTML signature and use the Image Source URLs returned from the above function to generate a HTML signature, then use placeholders for the code to replace these with the user's personal details (eg. name, job title, etc).
copyraw
/* *******************************************************************************
Function:       String fn_Settings_GenerateEmailSignatures()
Label:          Fn - Settings - Generate Email Signatures
Trigger:        Off a button / Standalone / Schedule to run daily @ 1am
Purpose:		Generates the email signature for all active users on their profile into the CRM settings.
Inputs:         -
Outputs:        -
Scope(s):		WorkDrive.team.ALL, WorkDrive.workspace.ALL, WorkDrive.files.ALL, WorkDrive.organization.READ, WorkDrive.teamfolders.ALL, WorkDrive.links.ALL, WorkDrive.DataTemplates.READ
				ZohoCRM.modules.ALL, ZohoCRM.org.READ, ZohoCRM.settings.ALL, ZohoCRM.users.ALL, ZohoCRM.notifications.ALL, ZohoCRM.Files.CREATE, ZohoCRM.coql.READ, ZohoCRM.Files.READ

Date Created:   2023-12-04 (Joel Lipman)
                - Initial release
				- Generates an email signature using the photo on the profile.
Date Modified:	???
                - ???

https://workdrive.zoho.com/apidocs/v1/filefoldersharing/shareeveryone			
******************************************************************************* */
l_PhoneString = List();
v_CompanyWebsite = "";
//
// get org details
m_Blank = Map();
m_OrgDetails = zoho.crm.invokeConnector("crm.getorg",m_Blank);
info m_OrgDetails.get("response");
if(!isNull(m_OrgDetails.get("response")))
{
	if(!isNull(m_OrgDetails.get("response").get("org")))
	{
		l_OrgDetails = m_OrgDetails.get("response").get("org");
		for each  m_OrgDetail in l_OrgDetails
		{
			if(!isNull(m_OrgDetail.get("phone")))
			{
				l_PhoneString.add(m_OrgDetail.get("phone"));
			}
			if(!isNull(m_OrgDetail.get("website")))
			{
				v_CompanyWebsite = m_OrgDetail.get("website");
			}
		}
	}
}
//
// run fn_Workdrive_HostImage function to get these src URLs:
v_Icon_TwitterHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890a\" style=\"width:15px;height:15px;margin:0;\" alt=\"Facebook\" />";
v_Icon_LinkedInHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890b\" style=\"width:15px;height:15px;margin:0;\" alt=\"LinkedIn\" />";
v_Icon_PinterestHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890c\" style=\"width:15px;height:15px;margin:0;\" alt=\"Instagram\" />";
v_Logos_PartnersHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890d\" style=\"width:300px;height:auto;margin:0;\" alt=\"Partners\" />";
//
// the generic signature for all users with merge fields enclosed with square tags:
v_RecodedSignature = "<table style=\"max-width:640px;font-family:Arial, Helvetica, sans-serif\"> <tr> <td rowspan=\"2\" style=\"max-width:160px;\"><img src=\"[AB-Image]\" style=\"width:150px;height:150px;\" alt=\"[AB-StaffName]\" /></td> <td style=\"min-width:250px;line-height:12pt;\"> <span style=\"font-weight:600;color:#005339;font-size: 12pt;\">[AB-StaffName]</span><br /> <span style=\"font-weight:600;color:#efdb00;font-size: 12pt;\">[AB-JobTitle]</span><br /> <span style=\"font-weight:700;color:#005339;font-size: 10pt;\">[AB-MobilePhone]</span><br /><a href=\"mailto:[AB-Email]\" style=\"text-decoration: none;\"><span style=\"font-weight:700;color:#005339;font-size: 10pt;text-transform:lowercase\">[AB-Email]</span></a><br /><a href=\"https://www.joellipman.com\" style=\"text-decoration: none;\"><span style=\"font-weight:700;color:#005339;font-size: 10pt;\">www.joellipman.com</span></a><br /> <div style=\"border-top:3px solid #efdb00;margin: 5px 0;padding:5px 0;\"> <a href=\"https://twitter.com/joel_lipman\">" + v_Icon_TwitterHTML + "</a> <a href=\"https://uk.linkedin.com/in/joelipman/\">" + v_Icon_LinkedInHTML + "</a> <a href=\"https://www.pinterest.co.uk/Joel_Lipman\">" + v_Icon_PinterestHTML + "</a> </div> </td> <td style=\"vertical-align: bottom;\"> " + v_Logos_PartnersHTML + " </td> </tr><tr> <td colspan=\"3\" style=\"text-align:justify;font-size:7pt;color:#ccc;line-height:10pt;padding:5px;\"> <p> <b>Important Terms & Conditions:</b><br /> <br /> <i>By choosing to purchase or hire ... </p> </td> </tr> </table>";
//
// get all active users in CRM
m_UserMapping = Map();
v_Endpoint = "https://www.zohoapis.eu/crm/v4/users?type=ActiveUsers";
r_Users = invokeurl
[
	url :v_Endpoint
	type :GET
	connection:"zcrm"
];
l_UserUpdates = List();
for each  m_User in r_Users.get("users")
{
	v_CurrentSignature = ifnull(m_User.get("signature"),"");
	//
	// criteria, only update signatures which aren't done?
	//if(v_CurrentSignature.length() < 1)
	//{
	//
	v_ImageURL = "";
	if(!isNull(m_User.get("Signature_Image")))
	{
		for each  m_SignatureImage in m_User.get("Signature_Image")
		{
			if(!isNull(m_SignatureImage.get("file_Id")))
			{
				//
				// get file object
				f_File = invokeurl
				[
					url :"https://www.zohoapis.eu/crm/v4/files?id=" + m_SignatureImage.get("file_Id")
					type :GET
					connection:"zcrm"
				];
				//
				// let's rename the file the name of the staff member along with the file type
				v_FileName = m_User.get("full_name");
				v_FileExtension = m_SignatureImage.get("extn");
				v_FileNameFull = v_FileName + "." + v_FileExtension;
				//
				// upload to profile photos folder (enter the workdrive last hash noted earlier)
				v_StaticFolder = "abcdefghijklmnopqrstuvwxyz12345678901";
				//
				// upload file to workdrive
				r_WorkdriveUpload = zoho.workdrive.uploadFile(f_File,v_StaticFolder,v_FileNameFull,true,"zworkdrive");
				info "Workdrive response:";
				info r_WorkdriveUpload;
				if(!isNull(r_WorkdriveUpload.get("data")))
				{
					//
					// set permissions to public and visible
					m_Headers = Map();
					m_Headers.put("Accept","application/vnd.api+json");
					for each  r_Data in r_WorkdriveUpload.get("data")
					{
						r_Attributes = r_Data.get("attributes");
						v_ResourceID = r_Attributes.get("resource_id");
					}
					//
					// generate permissions to send to workdrive
					m_Attributes = Map();
					m_Attributes.put("resource_id",v_ResourceID);
					m_Attributes.put("shared_type","everyone");
					// 34 files // 6 for folders
					m_Attributes.put("role_id","34");
					m_Data = Map();
					m_Data.put("attributes",m_Attributes);
					m_Data.put("type","permissions");
					m_Params = Map();
					m_Params.put("data",m_Data);
					r_Permissions = invokeurl
					[
						url :"https://www.zohoapis.eu/workdrive/api/v1/permissions"
						type :POST
						parameters:m_Params.toString()
						headers:m_Headers
						connection:"zworkdrive"
					];
					info "Workdrive Permissions:";
					info r_Permissions;
					//
					// response returns public permalink
					if(!isNull(r_Permissions.get("data")))
					{
						if(!isNull(r_Permissions.get("data").get("attributes")))
						{
							v_ImageURL = r_Permissions.get("data").get("attributes").get("permalink");
							v_ImageURL = v_ImageURL.replaceAll("https://workdrive.zohopublic.eu/file/","",true);
							//
							// replaced with URL taken on inspect element
							v_ImageURL = "https://previewengine-accl.zohopublic.eu/image/WD/" + v_ImageURL;
						}
					}
				}
			}
		}
	}
	// 
	v_Name = ifNull(m_User.get("full_name"),"");
	v_JobTitle = ifNull(m_User.get("Signature_Job_Title"),"");
	v_Phone = ifNull(ifNull(m_User.get("phone"),m_User.get("mobile")),"");
	v_Email = ifNull(m_User.get("email"),"");
	//
	l_PhoneString.add(v_Phone);
	v_PhoneStr = l_PhoneString.toString(" / ");
	//
	// merge with generic signature
	v_ThisSig = v_RecodedSignature;
	v_ThisSig = v_ThisSig.replaceAll("[AB-Image]",v_ImageURL,true);
	v_ThisSig = v_ThisSig.replaceAll("[AB-StaffName]",v_Name,true);
	v_ThisSig = v_ThisSig.replaceAll("[AB-JobTitle]",v_JobTitle,true);
	v_ThisSig = v_ThisSig.replaceAll("[AB-MobilePhone]",v_PhoneStr,true);
	v_ThisSig = v_ThisSig.replaceAll("[AB-Email]",v_Email,true);
	//
	// update signature on user profile
	m_UserSignature = Map();
	m_UserSignature.put("id",m_User.get("id"));
	m_UserSignature.put("signature",v_ThisSig);
	l_UserUpdates.add(m_UserSignature);
	//}
}
//
// if updates exist then update the users module with these new signatures
if(l_UserUpdates.size() > 0)
{
	m_Params = Map();
	m_Params.put("users",l_UserUpdates);
	r_UserUpdates = invokeurl
	[
		url :"https://www.zohoapis.eu/crm/v4/users"
		type :PUT
		parameters:m_Params.toString()
		connection:"zcrm"
	];
	info r_UserUpdates;
}
return "";
  1.  /* ******************************************************************************* 
  2.  Function:       string fn_Settings_GenerateEmailSignatures() 
  3.  Label:          Fn - Settings - Generate Email Signatures 
  4.  Trigger:        Off a button / Standalone / Schedule to run daily @ 1am 
  5.  Purpose:        Generates the email signature for all active users on their profile into the CRM settings. 
  6.  Inputs:         - 
  7.  Outputs:        - 
  8.  Scope(s):        WorkDrive.team.ALL, WorkDrive.workspace.ALL, WorkDrive.files.ALL, WorkDrive.organization.READ, WorkDrive.teamfolders.ALL, WorkDrive.links.ALL, WorkDrive.DataTemplates.READ 
  9.                  ZohoCRM.modules.ALL, ZohoCRM.org.READ, ZohoCRM.settings.ALL, ZohoCRM.users.ALL, ZohoCRM.notifications.ALL, ZohoCRM.Files.CREATE, ZohoCRM.coql.READ, ZohoCRM.Files.READ 
  10.   
  11.  Date Created:   2023-12-04 (Joel Lipman) 
  12.                  - Initial release 
  13.                  - Generates an email signature using the photo on the profile. 
  14.  Date Modified:    ??? 
  15.                  - ??? 
  16.   
  17.  https://workdrive.zoho.com/apidocs/v1/filefoldersharing/shareeveryone 
  18.  ******************************************************************************* */ 
  19.  l_PhoneString = List()
  20.  v_CompanyWebsite = ""
  21.  // 
  22.  // get org details 
  23.  m_Blank = Map()
  24.  m_OrgDetails = zoho.crm.invokeConnector("crm.getorg",m_Blank)
  25.  info m_OrgDetails.get("response")
  26.  if(!isNull(m_OrgDetails.get("response"))) 
  27.  { 
  28.      if(!isNull(m_OrgDetails.get("response").get("org"))) 
  29.      { 
  30.          l_OrgDetails = m_OrgDetails.get("response").get("org")
  31.          for each  m_OrgDetail in l_OrgDetails 
  32.          { 
  33.              if(!isNull(m_OrgDetail.get("phone"))) 
  34.              { 
  35.                  l_PhoneString.add(m_OrgDetail.get("phone"))
  36.              } 
  37.              if(!isNull(m_OrgDetail.get("website"))) 
  38.              { 
  39.                  v_CompanyWebsite = m_OrgDetail.get("website")
  40.              } 
  41.          } 
  42.      } 
  43.  } 
  44.  // 
  45.  // run fn_Workdrive_HostImage function to get these src URLs: 
  46.  v_Icon_TwitterHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890a\" style=\"width:15px;height:15px;margin:0;\" alt=\"Facebook\" />"
  47.  v_Icon_LinkedInHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890b\" style=\"width:15px;height:15px;margin:0;\" alt=\"LinkedIn\" />"
  48.  v_Icon_PinterestHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890c\" style=\"width:15px;height:15px;margin:0;\" alt=\"Instagram\" />"
  49.  v_Logos_PartnersHTML = "<img src=\"https://previewengine-accl.zohopublic.eu/image/WD/abcdefghijklmnopqrstuvwxyz1234567890d\" style=\"width:300px;height:auto;margin:0;\" alt=\"Partners\" />"
  50.  // 
  51.  // the generic signature for all users with merge fields enclosed with square tags: 
  52.  v_RecodedSignature = "<table style=\"max-width:640px;font-family:Arial, Helvetica, sans-serif\"> <tr> <td rowspan=\"2\" style=\"max-width:160px;\"><img src=\"[AB-Image]\" style=\"width:150px;height:150px;\" alt=\"[AB-StaffName]\" /></td> <td style=\"min-width:250px;line-height:12pt;\"> <span style=\"font-weight:600;color:#005339;font-size: 12pt;\">[AB-StaffName]</span><br /> <span style=\"font-weight:600;color:#efdb00;font-size: 12pt;\">[AB-JobTitle]</span><br /> <span style=\"font-weight:700;color:#005339;font-size: 10pt;\">[AB-MobilePhone]</span><br /><a href=\"mailto:[AB-Email]\" style=\"text-decoration: none;\"><span style=\"font-weight:700;color:#005339;font-size: 10pt;text-transform:lowercase\">[AB-Email]</span></a><br /><a href=\"https://www.joellipman.com\" style=\"text-decoration: none;\"><span style=\"font-weight:700;color:#005339;font-size: 10pt;\">www.joellipman.com</span></a><br /> <div style=\"border-top:3px solid #efdb00;margin: 5px 0;padding:5px 0;\"> <a href=\"https://twitter.com/joel_lipman\">" + v_Icon_TwitterHTML + "</a> <a href=\"https://uk.linkedin.com/in/joelipman/\">" + v_Icon_LinkedInHTML + "</a> <a href=\"https://www.pinterest.co.uk/Joel_Lipman\">" + v_Icon_PinterestHTML + "</a> </div> </td> <td style=\"vertical-align: bottom;\"> " + v_Logos_PartnersHTML + </td> </tr><tr> <td colspan=\"3\" style=\"text-align:justify;font-size:7pt;color:#ccc;line-height:10pt;padding:5px;\"> <p> <b>Important Terms & Conditions:</b><br /> <br /> <i>By choosing to purchase or hire ... </p> </td> </tr> </table>"
  53.  // 
  54.  // get all active users in CRM 
  55.  m_UserMapping = Map()
  56.  v_Endpoint = "https://www.zohoapis.eu/crm/v4/users?type=ActiveUsers"
  57.  r_Users = invokeUrl 
  58.  [ 
  59.      url :v_Endpoint 
  60.      type :GET 
  61.      connection:"zcrm" 
  62.  ]
  63.  l_UserUpdates = List()
  64.  for each  m_User in r_Users.get("users") 
  65.  { 
  66.      v_CurrentSignature = ifnull(m_User.get("signature"),"")
  67.      // 
  68.      // criteria, only update signatures which aren't done? 
  69.      //if(v_CurrentSignature.length() < 1) 
  70.      //{ 
  71.      // 
  72.      v_ImageURL = ""
  73.      if(!isNull(m_User.get("Signature_Image"))) 
  74.      { 
  75.          for each  m_SignatureImage in m_User.get("Signature_Image") 
  76.          { 
  77.              if(!isNull(m_SignatureImage.get("file_Id"))) 
  78.              { 
  79.                  // 
  80.                  // get file object 
  81.                  f_File = invokeUrl 
  82.                  [ 
  83.                      url :"https://www.zohoapis.eu/crm/v4/files?id=" + m_SignatureImage.get("file_Id") 
  84.                      type :GET 
  85.                      connection:"zcrm" 
  86.                  ]
  87.                  // 
  88.                  // let's rename the file the name of the staff member along with the file type 
  89.                  v_FileName = m_User.get("full_name")
  90.                  v_FileExtension = m_SignatureImage.get("extn")
  91.                  v_FileNameFull = v_FileName + "." + v_FileExtension; 
  92.                  // 
  93.                  // upload to profile photos folder (enter the workdrive last hash noted earlier) 
  94.                  v_StaticFolder = "abcdefghijklmnopqrstuvwxyz12345678901"
  95.                  // 
  96.                  // upload file to workdrive 
  97.                  r_WorkdriveUpload = zoho.workdrive.uploadFile(f_File,v_StaticFolder,v_FileNameFull,true,"zworkdrive")
  98.                  info "Workdrive response:"
  99.                  info r_WorkdriveUpload; 
  100.                  if(!isNull(r_WorkdriveUpload.get("data"))) 
  101.                  { 
  102.                      // 
  103.                      // set permissions to public and visible 
  104.                      m_Headers = Map()
  105.                      m_Headers.put("Accept","application/vnd.api+json")
  106.                      for each  r_Data in r_WorkdriveUpload.get("data") 
  107.                      { 
  108.                          r_Attributes = r_Data.get("attributes")
  109.                          v_ResourceID = r_Attributes.get("resource_id")
  110.                      } 
  111.                      // 
  112.                      // generate permissions to send to workdrive 
  113.                      m_Attributes = Map()
  114.                      m_Attributes.put("resource_id",v_ResourceID)
  115.                      m_Attributes.put("shared_type","everyone")
  116.                      // 34 files // 6 for folders 
  117.                      m_Attributes.put("role_id","34")
  118.                      m_Data = Map()
  119.                      m_Data.put("attributes",m_Attributes)
  120.                      m_Data.put("type","permissions")
  121.                      m_Params = Map()
  122.                      m_Params.put("data",m_Data)
  123.                      r_Permissions = invokeUrl 
  124.                      [ 
  125.                          url :"https://www.zohoapis.eu/workdrive/api/v1/permissions" 
  126.                          type :POST 
  127.                          parameters:m_Params.toString() 
  128.                          headers:m_Headers 
  129.                          connection:"zworkdrive" 
  130.                      ]
  131.                      info "Workdrive Permissions:"
  132.                      info r_Permissions; 
  133.                      // 
  134.                      // response returns public permalink 
  135.                      if(!isNull(r_Permissions.get("data"))) 
  136.                      { 
  137.                          if(!isNull(r_Permissions.get("data").get("attributes"))) 
  138.                          { 
  139.                              v_ImageURL = r_Permissions.get("data").get("attributes").get("permalink")
  140.                              v_ImageURL = v_ImageURL.replaceAll("https://workdrive.zohopublic.eu/file/","",true)
  141.                              // 
  142.                              // replaced with URL taken on inspect element 
  143.                              v_ImageURL = "https://previewengine-accl.zohopublic.eu/image/WD/" + v_ImageURL; 
  144.                          } 
  145.                      } 
  146.                  } 
  147.              } 
  148.          } 
  149.      } 
  150.      // 
  151.      v_Name = ifNull(m_User.get("full_name"),"")
  152.      v_JobTitle = ifNull(m_User.get("Signature_Job_Title"),"")
  153.      v_Phone = ifNull(ifNull(m_User.get("phone"),m_User.get("mobile")),"")
  154.      v_Email = ifNull(m_User.get("email"),"")
  155.      // 
  156.      l_PhoneString.add(v_Phone)
  157.      v_PhoneStr = l_PhoneString.toString(" / ")
  158.      // 
  159.      // merge with generic signature 
  160.      v_ThisSig = v_RecodedSignature; 
  161.      v_ThisSig = v_ThisSig.replaceAll("[AB-Image]",v_ImageURL,true)
  162.      v_ThisSig = v_ThisSig.replaceAll("[AB-StaffName]",v_Name,true)
  163.      v_ThisSig = v_ThisSig.replaceAll("[AB-JobTitle]",v_JobTitle,true)
  164.      v_ThisSig = v_ThisSig.replaceAll("[AB-MobilePhone]",v_PhoneStr,true)
  165.      v_ThisSig = v_ThisSig.replaceAll("[AB-Email]",v_Email,true)
  166.      // 
  167.      // update signature on user profile 
  168.      m_UserSignature = Map()
  169.      m_UserSignature.put("id",m_User.get("id"))
  170.      m_UserSignature.put("signature",v_ThisSig)
  171.      l_UserUpdates.add(m_UserSignature)
  172.      //} 
  173.  } 
  174.  // 
  175.  // if updates exist then update the users module with these new signatures 
  176.  if(l_UserUpdates.size() > 0) 
  177.  { 
  178.      m_Params = Map()
  179.      m_Params.put("users",l_UserUpdates)
  180.      r_UserUpdates = invokeUrl 
  181.      [ 
  182.          url :"https://www.zohoapis.eu/crm/v4/users" 
  183.          type :PUT 
  184.          parameters:m_Params.toString() 
  185.          connection:"zcrm" 
  186.      ]
  187.      info r_UserUpdates; 
  188.  } 
  189.  return ""

Source(s):
Category: Zoho :: Article: 863

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.