I have a support case record that has custom child...
# ask-stanley-ai
s
I have a support case record that has custom child records attached. I have a Suitelet that copies the support case record, but it does not copy the child record as well. How can I get the child records to also be copied onto the copied support case with this script?
c
AI generated answer (using internal Slack threads):
To copy the child records onto the copied support case, you will need to modify your Suitelet script to include the child records in the copy process. Here's a general approach: 1. When you copy the support case record, you should also retrieve the child records associated with it. You can do this by using a search operation on the child record type, filtering by the parent record's internal ID. 2. Once you have the child records, you can iterate over them and create new child records that are identical to the originals. You can do this by loading each child record, copying its field values, and then creating a new child record with those values. 3. After creating the new child records, you need to associate them with the copied support case record. You can do this by setting the parent field on each child record to the internal ID of the copied support case record. 4. Finally, save the new child records. Here's a simplified example of how you might do this in SuiteScript 2.0:
Copy code
javascript
var supportCaseRecord = record.load({
    type: 'supportcase',
    id: originalSupportCaseId
});

var copiedSupportCase = record.copy({
    type: 'supportcase',
    id: originalSupportCaseId
});

var childRecords = search.create({
    type: 'customrecord_child',
    filters: [
        ['custrecord_parent', 'anyof', originalSupportCaseId]
    ]
}).run().getRange({start: 0, end: 1000});

childRecords.forEach(function(childRecord) {
    var copiedChildRecord = record.copy({
        type: 'customrecord_child',
        id: childRecord.id
    });
    copiedChildRecord.setValue('custrecord_parent', copiedSupportCase.id);
    copiedChildRecord.save();
});
Please replace 'supportcase', 'customrecord_child', and 'custrecord_parent' with your actual record type and field IDs. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.845337
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.83404541
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.831848145
Please provide your feedback on this answer.