const context = { }; async function getPhoneNumbers() { const phoneFieldsDropdown = document.getElementById('phone-fields-dropdown'); const selectedValues = Array.from(phoneFieldsDropdown.options).filter(option => option.selected).map(option => option.value); if (!selectedValues.length) { return showAlert('error', 'Please select atleast one phone field'); } const ids = context.recordIds.map(x => `'${x}'`).join(', '); const select_query = `SELECT ${selectedValues.join(', ')} FROM ${context.module} WHERE id in (${ids})`; const {data} = await ZOHO.CRM.API.coql({select_query}); const phoneNumbers = []; data.forEach(x => { Object.keys(x).forEach(key => { if (key !== 'id' && x[key]) { phoneNumbers.push(x[key]); } }); }); return phoneNumbers; } ZOHO.embeddedApp.on("PageLoad", function (data) { // Get the current module name and selected record ids const {Entity, EntityId} = data; context.module = Entity; context.recordIds = EntityId; // Get the phone fields for current module ZOHO.CRM.META.getFields({Entity}).then( function (response) { const {fields} = response; const phoneFields = fields.filter(x => x.data_type === 'phone').map(x => ({value: x.api_name, label: x.display_label })); new Choices('#phone-fields-dropdown', { removeItemButton: true, choices: phoneFields, placeholder: true, placeholderValue: 'Select Phone Fields to be used' }); ZOHO.CRM.UI.Resize({height:"400", width:"700"}); }); // Initialize twilio credentials twilio.init("$YOUR_ACCOUNT_SID", "$YOUR_AUTH_TOKEN", "+YOUR_TWILIO_NUMBER"); }) ZOHO.embeddedApp.init(); |
Writer is a powerful online word processor, designed for collaborative work.