I have a custom record which has a child custom re...
# ask-stanley-ai
s
I have a custom record which has a child custom record that act as line items. When the user selects a button, I want it to create a quote with all the line items on it, while only setting the item, quantity, and price, and sourcing the rest of the info. How can I do this with SuiteScript
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. ****** To create a quote with line items from a custom record, you can use SuiteScript. Here's a general approach: 1. Create a User Event Script: This script will be triggered when the user selects a button on the custom record. 2. Gather Line Item Data: In the User Event Script, you can gather the line item data from the child custom record. You can use the
record.selectNewLineItem
and
record.setCurrentLineItemValue
methods to do this. 3. Create a Quote Record: Still within the User Event Script, you can create a new quote record using the
record.create
method. 4. Set Line Items on Quote: For each line item gathered from the custom record, you can use the
record.selectNewLine
and
record.setCurrentSublistValue
methods to set the line items on the quote. 5. Save the Quote: Finally, you can save the quote using the
record.save
method. Here's a simplified example of what the code might look like:
Copy code
javascript
var customRecord = record.load({
    type: 'customrecord_my_custom_record',
    id: myCustomRecordId
});

var quote = record.create({
    type: record.Type.ESTIMATE,
    isDynamic: true
});

for (var i = 0; i < customRecord.getLineCount({sublistId: 'recmachcustrecord_child_record'}); i++) {
    var itemId = customRecord.getSublistValue({
        sublistId: 'recmachcustrecord_child_record',
        fieldId: 'custrecord_item',
        line: i
    });
    var quantity = customRecord.getSublistValue({
        sublistId: 'recmachcustrecord_child_record',
        fieldId: 'custrecord_quantity',
        line: i
    });
    var price = customRecord.getSublistValue({
        sublistId: 'recmachcustrecord_child_record',
        fieldId: 'custrecord_price',
        line: i
    });

    quote.selectNewLine({
        sublistId: 'item'
    });
    quote.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        value: itemId
    });
    quote.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'quantity',
        value: quantity
    });
    quote.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'rate',
        value: price
    });
    quote.commitLine({
        sublistId: 'item'
    });
}

var quoteId = quote.save();
Please note that this is a simplified example and you may need to adjust it to fit your specific needs. For example, you may need to set additional fields on the quote, handle errors, or optimize for performance.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.851837635
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.850170314
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.849862218
Please provide your feedback on this answer.