Optimizing code in custom functions
It is advisable to optimize code by verifying if the necessary data has already been fetched rather than rewriting code to fetch the data again. Always verify the value of the field before executing any operation. This approach helps eliminate redundancy in the code.
When making API calls or function calls, it is crucial to check for null values consistently. It is considered a best practice to ensure the existence of a value in optional or relevant fields before carrying out any operations associated with those fields.
For instance, it is advisable to check if the custom field cf_category has a value or not before executing the code or updating the field.
Ensure data availability before any operation
When making an API call, it is advisable to check the details of the retrieved results before fetching related or identical data.
For instance, if the ticketList API is called and it includes both ticketId and ticketNumber, it is recommended to utilize the ticketNumber data already present in the ticketList when fetching the ticketNumber using a function.
Use the include option in API calls
Instead of making two separate API calls to retrieve ticket details like
ticketOwner and
assignee information, a more efficient approach would be to use a single API call with the
include option. This option allows users to fetch the necessary additional details in a single API call instead of making multiple calls. Learn more about
include options.
Check data values before any operation
Avoiding unnecessary modifications to records helps ensure efficiency.
For instance, if you wish to mark a ticket as closed, verify whether the ticket is already closed or not
Utilize the sendReply option for email threads
The limit for sending emails is 2,500 per day. When using the sendmail function, the emails sent will not be logged in the ticket thread. However, you can use the sendReply function without any limits for sending emails, and the emails will be recorded in the thread conversation.