I have multiple subsidiaries and, for user events,...
# ask-stanley-ai
m
I have multiple subsidiaries and, for user events, we are working with IF conditions to execute some lines of code for a specific subsidiary. I see that the deployment record has the subsidiary audience. Is it better in terms of performance to handle the subsidiary through the record deployment configuration ? Or is it less cost to add multiple IF conditions inside the suite script ?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** In terms of performance, it is generally more efficient to handle the subsidiary through the record deployment configuration rather than adding multiple IF conditions inside the SuiteScript. There are a few reasons for this: 1. Reduced Script Execution Time: Each time a script is executed, there is a cost associated with starting it up. If you have multiple IF conditions in your script, it will take longer to execute, which could impact performance. 2. Simplified Code Maintenance: By handling the subsidiary through the record deployment configuration, you can avoid hardcoding subsidiary-specific information in your script. This makes your code easier to maintain and update. 3. Improved Scalability: If you add new subsidiaries in the future, you can simply update the deployment configuration rather than modifying your script. However, it's important to note that this approach may not be suitable for all scenarios. For example, if you have a complex business logic that requires different code execution paths for different subsidiaries, using IF conditions in your script might be necessary. Here's an example of how you can use an object map to handle different subsidiaries:
Copy code
javascript
// Map subsidiary id to email template id
var emailTemplates = {
    1: 101,
    2: 102,
    3: 103
};

var subsidiaryId = record.getValue({ fieldId: 'subsidiary' });

// Get the template for this subsidiary, default to 105 if no template is specified.
var templateId = emailTemplates[subsidiaryId] || 105;
In this example, the
emailTemplates
object maps subsidiary IDs to email template IDs. The
subsidiaryId
is retrieved from the record, and the corresponding
templateId
is retrieved from the
emailTemplates
object. If no template is specified for a subsidiary, a default template ID of 105 is used.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842773438
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.816467404
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.814941406
Please provide your feedback on this answer.