Running an automotive repair garage means you often collect photos of vehicles from customers to help you assess the damage and provide accurate quotes. If you have these photos uploaded to an image upload field in a deal record, it's advisable to add them to its Attachments tab. This practice ensures all related files of a record are accessible in one location without navigating through individual fields. However, manually downloading photos and re-uploading them is a time consuming task. What if you could add the photos uploaded in the field to the Attachments tab at the click of a button? This is where a custom function can be handy.
To spare you the effort of manual work, you can create a custom function that automatically adds photos to the Attachments tab. You can then link this function to a custom button within the deals module. After uploading photos to the file upload field, click the custom button to trigger the function and add the photos to the Attachments tab. Read on to learn more.
Note: Since we don’t have a trigger based on edits to the image upload field, we cannot set up a workflow rule in the deals module.
Permissions and availability
- Users with the Manage Extensibility permission can create connections and write custom functions.
- Users with the Modules Customization permission can add custom fields and buttons.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Create a Zoho OAuth connection with the required scopes for your Zoho CRM, as detailed in the "Create Connection" section below. Learn more
- Add a custom Image Upload field in the Deals module. This field will hold photos uploaded to the deal records. Learn more
- Create and link the button with the custom function, as detailed in the "Create a button" section below. Learn more
- Test the workflow rule in a sandbox before deploying it in your production environment. Learn more
Create a connection
The first step is to create an OAuth connection in your Zoho CRM account.
- Go to Setup > Developer Space > Connections.
- Click Create Connection.
- Select Zoho OAuth under Default Services.
- Specify a Connection Name.
You will enter this name in the code snippet below. - Select the following Scopes to request access:
- ZohoCRM.modules.ALL
- ZohoCRM.Files.READ
- Click Create and Connect.
- Click Connect, then click Accept to confirm authorization of access for the scope requested by the client.
Add a custom field
The next step is to add a custom image upload field to the Deals module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Deals module to open the layout editor.
- Drag and drop the Image Upload field from the New Fields tray to the desired section of the layout.
- Name the image upload field (e.g., "Vehicle Photos") and define its properties as required.
- Once you have finished, click Save and Close.
Create a button
The final step is to create a custom button that, when clicked, adds photos to the Attachments tab.
- Navigate to Setup > Customization > Modules and Fields > Deals > Buttons > Create New Button.
- Provide a name for the button. For example: "Attach Photos".
Add a description (optional). - Choose the layouts where you want the button to be placed.
- Specify the button's placement as In Record and its position on the page as Details.
- Select the action to be performed as Writing Function.
- Provide a name and display name for the function, and click Create.
- On the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Enter the name as dealId, select the value as Deals - Deal Id, then click Save.
- Save the function.
- Select the profiles who can view this custom button.
- Click Save.
The code
resp = invokeurl
[
url :"https://www.zohoapis.com/crm/v7/Deals/" + dealId
type :GET
connection:"connectionname"
];
fileid = resp.get("data").get(0).get("Vehicle_Photos").get(0).get("File_Id__s");
info fileid;
file = invokeurl
[
url :"https://www.zohoapis.com/crm/v7/files?id=" + fileid
type :GET
connection:"connectionname"
];
info file;
upload = zoho.crm.attachFile("Deals",dealId,file);
info upload;
return "enter success message";
Notes
- Replace "connectionname" with the name of the connection you specified while creating the connection (see the Create a connection section above).
- Make sure to use the accurate API names for their corresponding fields (e.g., "Vehicle Photos") in the code snippet. Learn more
- Enter a success message to display after clicking the button on the deal record.
- As the API URLs differ for each data center, you should identify your account's data center and use the corresponding domain in the URL. For example, for India, use https://www.zohoapis.in/crm.
- You can add more buttons if multiple image upload fields exist in the layout.
- The above code is an example of adding photos uploaded to a record's image upload field to its Attachments tab at the click of a button. You can use this code to add photos in any other module, such as leads or custom, by modifying the module name and parameters.
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to the Deals module.
- Open the deal record where you want to add photos to the Attachments tab.
- Upload a photo to the image upload field (i.e., Vehicle Photos) you've added to the layout, click Attach, then click Save.
- Click the custom button you added to the top-right area.
- Check whether the uploaded photo appears in the Attachments tab of the Related List section.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleDeals
- Trigger PointCustom Button
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST