A very quick article on a small client script to set the Account field on the Quote from a lookup field on the Deal record.
Why?
The use-case here is that I have a client who is a supplier. The opportunity (aka Deal) will be in the end customer's name so it is their name in the Account field. When a quote is raised off the opportunity, the quote needs to be targeted to the distributor/reseller but if you click on the Add New Quote from the opportunity record, it puts the end customer in the Account field (maps Deal Account Name to Quote Account Name).
How?
We want this to happen as soon as a CRM user clicks on the plus symbol or "Add New" in the quotes related list section of the Deal record. In this example, on the Deal/Opportunity record, I have an Account Name field (the end customer), and a "Distributor" (lookup to the Accounts) as well as a "Reseller" (another lookup to Accounts) field. EITHER the Distributor or Reseller field will be populated but this will be the company the quote should be raised for.
Setup up the Client Script:
- Login to ZohoCRM > Setup (cog icon next to profile photo) > Developer Hub > Client Script > New Script
- Give it a name, I'm calling mine Quotes - Map Distributor/Reseller
- Give it a description. I said "Maps the distributor/reseller from the opportunity into the account.".
- Category is Module, Page is Create Page (Standard) (change this depending on if you're using a canvas or not)
- Module is Quotes
- Type is Page Event
- Event is onLoad
- Click on the button Next
The code:
copyraw
/* *******************************************************************************
Function: Quotes - Map Distributor/Reseller
Label: Quotes - Map Distributor/Reseller
Page Details
Category Module
Page Create Page (Standard)
Module Quotes
Layout Standard
Event Details
Event Type Page Event
Event onLoad
Purpose: Maps the distributor/reseller from the opportunity into the account.
Inputs: -
Outputs: -
Date Created: 2026-01-20 (Joel Lipman)
- Initial release
Date Modified: ???
- ???
More Information:
https://www.zohocrm.dev/explore/client-script/webapi/Modules#fetchById
******************************************************************************* */
var f_Opportunity = ZDK.Page.getField('Deal_Name');
var o_OpportunityLookup = f_Opportunity.getValue();
if (o_OpportunityLookup != null) {
var v_OppID = o_OpportunityLookup.id;
var o_OppDetails = ZDK.Apps.CRM.Deals.fetchById(o_OpportunityLookup.id);
if (o_OppDetails._Distributor_Lookup_Id != null) {
// get distributor record
var o_DistDetails = ZDK.Apps.CRM.Accounts.fetchById(o_OppDetails._Distributor_Lookup_Id);
// set quote account lookup
var f_Account = ZDK.Page.getField('Account_Name');
f_Account.setValue({ id: o_OppDetails._Distributor_Lookup_Id, name: o_DistDetails.Account_Name });
}
if (o_OppDetails._Reseller_Lookup_Id != null) {
// get reseller record
var o_ResellerDetails = ZDK.Apps.CRM.Accounts.fetchById(o_ResellerDetails._Reseller_Lookup_Id);
// set quote account lookup
var f_Account = ZDK.Page.getField('Account_Name');
f_Account.setValue({ id: o_ResellerDetails._Reseller_Lookup_Id, name: o_ResellerDetails.Account_Name });
}
}
- /* *******************************************************************************
- Function: Quotes - Map Distributor/Reseller
- Label: Quotes - Map Distributor/Reseller
- Page Details
- Category Module
- Page Create Page (Standard)
- Module Quotes
- Layout Standard
- Event Details
- Event Type Page Event
- Event onLoad
- Purpose: Maps the distributor/reseller from the opportunity into the account.
- Inputs: -
- Outputs: -
- Date Created: 2026-01-20 (Joel Lipman)
- - Initial release
- Date Modified: ???
- - ???
- More Information:
- https://www.zohocrm.dev/explore/client-script/webapi/Modules#fetchById
- ******************************************************************************* */
- var f_Opportunity = ZDK.Page.getField('Deal_Name');
- var o_OpportunityLookup = f_Opportunity.getValue();
- if (o_OpportunityLookup != null) {
- var v_OppID = o_OpportunityLookup.id;
- var o_OppDetails = ZDK.Apps.CRM.Deals.fetchById(o_OpportunityLookup.id);
- if (o_OppDetails._Distributor_Lookup_Id != null) {
- // get distributor record
- var o_DistDetails = ZDK.Apps.CRM.Accounts.fetchById(o_OppDetails._Distributor_Lookup_Id);
- // set quote account lookup
- var f_Account = ZDK.Page.getField('Account_Name');
- f_Account.setValue({ id: o_OppDetails._Distributor_Lookup_Id, name: o_DistDetails.Account_Name });
- }
- if (o_OppDetails._Reseller_Lookup_Id != null) {
- // get reseller record
- var o_ResellerDetails = ZDK.Apps.CRM.Accounts.fetchById(o_ResellerDetails._Reseller_Lookup_Id);
- // set quote account lookup
- var f_Account = ZDK.Page.getField('Account_Name');
- f_Account.setValue({ id: o_ResellerDetails._Reseller_Lookup_Id, name: o_ResellerDetails.Account_Name });
- }
- }
Category: Zoho CRM :: Article: 1719


