Skip to content

Commit

Permalink
Check for null Organization const after API Call (#16)
Browse files Browse the repository at this point in the history
* check for null organization obj, docs
  • Loading branch information
physik932 authored Oct 11, 2019
1 parent aedab4e commit 1394ed7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/javascripts/modules/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,24 @@ async function getContext() {
const ticketFields = await client.request(getTicketData(ticket.id));

/**
* Tickets sometimes have a null organization. If it is not null, get any custom fields for the org
* and assign them to the ticket organization object.
* Ticket organization is based on the nature of how the ticket was created.
* If an organization is available and we can access it, we'll assign the fields.
*
* From Zendesk (https://support.zendesk.com/hc/en-us/articles/203690926-Updating-ticket-requesters-and-organizations):
* - When a user who belongs to multiple organizations submits a ticket by email, it is assigned to their
* - default organization. When the user creates a ticket in your Help Center, or when an agent creates a
* - ticket on behalf of the user, the user or agent can select the organization for the ticket.
*/
if (ticket.organization) {
const { organization } = await client.request(getOrganizationData(ticket.organization.id));
ticket.organization.organization_fields = organization.organization_fields;
try {
const { organization } = await client.request(getOrganizationData(ticket.organization.id))

if (organization) {
ticket.organization.organization_fields = organization.organization_fields;
}
} catch (error) {
console.error(`Error retrieving Organization fields for ${ticket.organization.id}: ${error}`)
}
}

ticket = assignTicketFields(ticket, ticketFields);
Expand Down

0 comments on commit 1394ed7

Please sign in to comment.