CRM : Function to add user name to text field

CRM : Function to add user name to text field

I have a lookup field in a module that is linked to the CRM users so we can assign a Project Lead to the customer. Sadly Zoho Marketing Automation doesn't sync Lookup fields so I need to extract information from the lookup to text fields:

Lookup field : Project_Lead
Text Field : Project_Lead_Name
Text Field : Project_Lead_Email

I want this to happen when the Project Lead is chosen via the dropdown and know this can be done via workflow with a custom function - I just can't find how to correctly write the deluge to pull the associated details and update the other fields.

I've used a bit of GPT to get me started, but it can't get the nuance right and I don't have the experience.

  1. void automation.Customer_Update_ProjectLeadName()
  2. {
  3. userId = input.Project_Lead;
  4. if(userId != null)
  5.   {
  6.   userDetails = zoho.crm.getRecordById("users", userId.toLong());
  7.   if(userDetails.containKey("full_name"))
  8.      {
  9.         fullName = userDetails.get("full_name");
  10.         updateMap = map();
  11.         updateMap.put("Project_Lead_Name", fullName);
  12.         zoho.crm.updateRecord(input.module, input.id.toLong(), updateMap);
  13.         }
  14.      }