Custom Function: Populate the address information from Lead/Contact into the custom fields in the Event

Custom Function: Populate the address information from Lead/Contact into the custom fields in the Event

A few prerequisites: 

1. Events should be associated to a lead or contact.
2. Events should have the address fields that are mentioned in the custom function.


void workflowspace.UpdateContactInfo(int eventId,int leadId,int contactId)
{
    eventId = input.eventId;
    eventIdStr = input.eventId.toString();
    eventDetails = zoho.crm.getRecordById("Events",input.eventId);
    contactId = input.contactId;
    leadId = input.leadId;
    if(input.leadId  !=  null)
    {
        leadId = (eventDetails.get("RELATEDTOID")).toLong();
        leadDetails = zoho.crm.getRecordById("Leads",input.leadId);
        eventStreet = ifnull(leadDetails.get("Street"),"");
        eventCity = ifnull(leadDetails.get("City"),"");
        eventState = ifnull(leadDetails.get("State"),"");
        eventCountry = ifnull(leadDetails.get("Country"),"");
    }
    else if(input.contactId  !=  null)
    {
        contactIdLong = input.contactId.toLong();
        contactDetails = zoho.crm.getRecordById("Contacts",contactIdLong);
        eventStreet = ifnull(contactDetails.get("Mailing Street"),"");
        eventCity = ifnull(contactDetails.get("Mailing City"),"");
        eventState = ifnull(contactDetails.get("Mailing State"),"");
        eventCountry = ifnull(contactDetails.get("Mailing Country"),"");
    }
    eventMap = map();
    eventMap.put("Street",eventStreet);
    eventMap.put("City",eventCity);
    eventMap.put("State",eventState);
    eventMap.put("Country",eventCountry);
    updateEvents = zoho.crm.updateRecord("Events",eventIdStr,eventMap);


Sincerely,
Prakash,
Zoho Customer Support