Shelby Owens
06/06/2025, 3:49 PMCeligo AI
06/06/2025, 3:49 PMAI 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. ****** To achieve the functionality of having a field called "total cost" on the parent case record that shows the sum of the "cost" field on all child records, you can use a combination of SuiteScript and SuiteQL. Here are the steps you can follow: 1. Create a new custom field on the parent record to hold the "total cost". This field will be updated by the script. 2. Write a SuiteScript that triggers on the create/update of a child record. This script will calculate the sum of the "cost" field on all child records related to the parent. 3. Use SuiteQL within the script to efficiently retrieve and sum the "cost" field values from the child records. SuiteQL supports multiple joins and left outer joins, which can be useful in this scenario. 4. Update the "total cost" field on the parent record with the calculated sum. Here's a high-level example of what the SuiteScript might look like:
javascript
function afterSubmit(scriptContext) {
if (scriptContext.type === scriptContext.UserEventType.CREATE || scriptContext.type === scriptContext.UserEventType.EDIT) {
var childRecord = scriptContext.newRecord;
var parentRecordId = childRecord.getValue('parent');
var suiteql = "SELECT SUM(cost) FROM customrecord_child WHERE parent = " + parentRecordId;
var sum = query.runSuiteQL(suiteql).asMappedResults();
record.submitFields({
type: 'customrecord_parent',
id: parentRecordId,
values: {
'custrecord_total_cost': sum[0].value
}
});
}
}
Please note that you'll need to replace 'customrecord_child', 'parent', 'cost', 'customrecord_parent', and 'custrecord_total_cost' with your actual record and field IDs. Also, this is a simplified example and may need to be adjusted based on your specific requirements and environment.Celigo AI
06/06/2025, 3:49 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.853065491
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851787329
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83962971
Celigo AI
06/06/2025, 3:49 PM