A quick article to remind me how to quickly get a field from a user's settings based on the owner of a record.
Why?
A client had added a custom lookup field to the users settings called "Division" (similar to team name) and wanted any Opportunity record to have a field showing the user's Division. This would help in reporting later down the line.
How?
The following code snippet will get the Opportunity/Deal/Potential record details, then get the Owner frrom the CRM users table, find the value of the custom field and search for this (if it is a lookup to a module - only returns as string), and updates the Opportunity/Deal/Potential record. In this example, the custom field is called "Division":
copyraw
	
//
// init
v_DealID = ifnull(p_DealID,0);
r_DealDetails = zoho.crm.getRecordById("Deals",v_DealID);
//
// Map users/owners division to this deal
if(!isnull(r_DealDetails.get("Owner")))
{
	l_Users = zoho.crm.getRecordById("users",r_DealDetails.get("Owner").get("id"));
	for each  r_UserDetails in l_Users
	{
		m_UserDetails = r_UserDetails.toMap();
		if(!isnull(m_UserDetails.get("Division")))
		{
			v_DivisionID = "";
			v_DivisionName = m_UserDetails.get("Division");
			l_CrmDivisions = zoho.crm.searchRecords("Divisions","Name:equals:" + v_DivisionName);
			for each  r_Division in l_CrmDivisions
			{
				if(!isnull(r_Division.get("Name")))
				{
					if(r_Division.get("Name") == v_DivisionName)
					{
						v_DivisionID = r_Division.get("id");
					}
				}
			}
			if(v_DivisionID != "")
			{
				m_UpdateDeal = Map();
				m_UpdateDeal.put("Division",v_DivisionID);
				r_UpdateDeal = zoho.crm.updateRecord("Deals",v_DealID,m_UpdateDeal);
				info r_UpdateDeal;
			}
		}
		break;
	}
}
	- //
- // init
- v_DealID = ifnull(p_DealID,0);
- r_DealDetails = zoho.crm.getRecordById("Deals",v_DealID);
- //
- // Map users/owners division to this deal
- if(!isnull(r_DealDetails.get("Owner")))
- {
- l_Users = zoho.crm.getRecordById("users",r_DealDetails.get("Owner").get("id"));
- for each r_UserDetails in l_Users
- {
- m_UserDetails = r_UserDetails.toMap();
- if(!isnull(m_UserDetails.get("Division")))
- {
- v_DivisionID = "";
- v_DivisionName = m_UserDetails.get("Division");
- l_CrmDivisions = zoho.crm.searchRecords("Divisions","Name:equals:" + v_DivisionName);
- for each r_Division in l_CrmDivisions
- {
- if(!isnull(r_Division.get("Name")))
- {
- if(r_Division.get("Name") == v_DivisionName)
- {
- v_DivisionID = r_Division.get("id");
- }
- }
- }
- if(v_DivisionID != "")
- {
- m_UpdateDeal = Map();
- m_UpdateDeal.put("Division",v_DivisionID);
- r_UpdateDeal = zoho.crm.updateRecord("Deals",v_DealID,m_UpdateDeal);
- info r_UpdateDeal;
- }
- }
- break;
- }
- }
Category: Zoho :: Article: 762
	

 
			      
						  
                 
						  
                 
						  
                 
						  
                 
						  
                 
 
 

 
 
Add comment