Related Lists
The Related Lists feature allows you to fetch and view data from within the app as well as from other third-party services. This comes in handy when you want to cross-reference data from different entities.
You can create related lists for the following modules:
- Items
- Vendors
- Purchase Orders
- Purchase Receives
- Bills
- Vendor Credits
Insight: You can create a maximum of 10 related lists for each module. For example, 10 for Purchase Orders, 10 for Vendors, and so on.
Create a Related List
There are two ways to create a related list:
Using a Lookup Custom Field
The Lookup custom field allows you to pull data from one module and access it inside another module in Zoho Spend. When you create a lookup field in one module, its associated details will be available as a related list in the other module.
Using a Deluge Script
With Deluge Scripts, you can connect Zoho Spend with other third-party services to access their data.
To create a related list using Deluge:
- Go to Settings on the left sidebar.
(OR)
Click Settings in the top right corner of the page. - Select the module for which you want to create a related list.
- Navigate to the Related Lists tab.
- Click + New Related List in the top right corner.
- Enter the Related List Name.
- Select Who can view this related list?. You can either choose Only Me and Everyone.
- Write a deluge script to fetch data from the connected third-party service.
- Click Save, or Save and Execute to run the function.
The lists will be displayed under the Related Lists tab in the respective modules.
Note:
- The deluge script must return a map that contains ‘header_context’ and ‘data’ in the following format:
{ header_context: [ { key: 'vendor_name', value: 'Vendor Name' }, { key: 'bill_number', value: 'Bill Number } ], data: [ { vendor_name: <vendor_name>, bill_number: <bill_number> } ] } - There are two ways to specify the value of the data node:
- Display as a string:
vendor_name: <vendor_name> - Display as a hyperlink:
vendor_name: { "value": <vendor_name>, "isExternal":true, // To open the link in separate tab. "link": <web_url_path> }
- Display as a string:
- The Deluge script will return a map that can also contain ‘page_context’. When you try fetching all the transaction records at once, it may result in a longer page response time. To resolve this issue, the ‘page_context’ can be helpful in splitting the records based on pages and fetching them faster. For example, if you have 50 transaction records for your vendors, you can split those records into 10 records per page and fetch the required data faster using page_context.
- If you want to fetch records based on pages using the Deluge script, you will have to add ‘page_context’ in the Deluge script returned value, and it should have the following properties:
- page: string
- per_page: string
- has_more_page: boolean (Should be set as false when you reach the last set of data)
{ header_context: [{...}, {...}], data: [{...}], page_context: { per_page: '10', page: '1', has_more_page: true/false } }
Sample Function
Here’s a scenario and a sample function to understand related lists better:
Scenario: Zylker uses Zoho Spend for their purchases, and Zoho Desk to address their customer queries. Now, the admin can write and execute a deluge script to fetch the customer happiness rating from Zoho Desk, and show the consolidated data in a tabular form under each customer in Zoho Spend.
{
searchMap = Map();
searchMap.put('fullName',customer.get("contact_name"));
searchMap.put('orgId',XXXXX);//Zoho desk orgId
searchList = invokeurl
[
url :"https://desk.zoho.in/api/v1/contacts/search"
type :GET
parameters:searchMap
connection:"zohodesk"
];
contacts = searchList.get('data').toList();
contact = contacts.get('0');
contactId = contact.get('id');
fromIndex = (page_context.get('page').toNumber() - 1) * page_context.get('per_page').toNumber();
happinessList = invokeurl
[
url :"https://desk.zoho.in/api/v1/customerHappiness?include=contacts,agents,tickets&department=allDepartment&from=" + fromIndex + "&limit=10&contactId=" + contactId
type :GET
connection:"zohodesk"
];
happinessList = happinessList.get('data').toList();
headerData = List();
headerData.add({"key":"ticket.ticketNumber","value":"Ticket Number"});
headerData.add({"key":"rating","value":"Rating"});
headerData.add({"key":"feedback","value":"Feedback"});
headerData.add({"key":"agent.lastName","value":"Agent Last Name"});
happinessCount = invokeurl
[
url :"https://desk.zoho.in/api/v1/customerHappiness/count?department=allDepartment&contactId=" + contactId
type :GET
connection:"zohodesk"
];
happinessCount = happinessCount.get('allDepartment');
totalCount = happinessCount.get('okay') + happinessCount.get('bad') + happinessCount.get('good');
pageContext = Map();
pageContext.put('page',page_context.get('page'));
pageContext.put('per_page',page_context.get('per_page'));
pageContext.put('has_more_page',false);
if(totalCount >= page_context.get('page').toNumber() * page_context.get('per_page').toNumber())
{
pageContext.put('has_more_page',true);
}
resultMap = Map();
resultMap.put("header_context",headerData);
resultMap.put("data",happinessList);
resultMap.put("page_context",pageContext);
return resultMap;
}
Edit a Related List
Note: You can only edit related lists created using Deluge scripts. To edit a related list created using a lookup custom field, you need to edit the lookup field.
Here’s how you can edit a related list:
- Go to Settings on the left sidebar.
(OR)
Click Settings in the top right corner of the page. - Select the module for which you want to edit the related list.
- Navigate to the Related Lists tab.
- Hover over the list that you want to edit.
- Click the Dropdown icon and select Edit.
- Make the necessary changes and click Save.
Mark a Related List as Inactive
You can temporarily disable a related list by marking it as inactive. Here’s how:
- Go to Settings on the left sidebar.
(OR)
Click Settings in the top right corner of the page. - Select the module in which you created the related list.
- Navigate to the Related Lists tab.
- Hover over the list that you want to mark as inactive.
- Click the Dropdown icon and click Mark as Inactive.
Mark an Inactive Related List as Active
Here’s how you can mark an inactive related list as active:
- Go to Settings on the left sidebar.
(OR)
Click Settings in the top right corner of the page. - Select the module in which you created the related list.
- Navigate to the Related Lists tab.
- Hover over the list that you want to mark as active.
- Click the Dropdown icon and click Mark as Active.
Delete a Related List
Note: You can only delete the related lists created using Deluge scripts. To delete a related list created using a lookup custom field, you need to delete the lookup field.
Here’s how you can delete a related list:
- Go to Settings on the left sidebar.
(OR)
Click Settings in the top right corner of the page. - Select the module for which you want to delete the related list.
- Navigate to the Related Lists tab.
- Hover over the list that you want to delete.
- Click the Dropdown icon and select Delete.
- Confirm your action by clicking OK in the pop-up.