How do I create client suitescript that creates a ...
# ask-stanley-ai
s
How do I create client suitescript that creates a button that when clicked, runs a suitelet in the background, where that suitelet creates a quote record?
c
AI generated answer (using internal Slack threads):
To create a client SuiteScript that creates a button which, when clicked, runs a Suitelet in the background that creates a quote record, you can follow these steps: 1. Create a User Event Script that adds a button to the form. This script will be triggered before the form is loaded. Here is a sample code snippet:
Copy code
javascript
const beforeLoad = (context) => {
    context.form.addButton({
        id: 'custpage_quote_button',
        label: 'Create Quote',
        functionName: 'createQuoteForm'
    });
    context.form.clientScriptModulePath = "SuiteScripts/Your_Client_Script.js";
};
return {beforeLoad}
2. Create a Client Script that will be triggered when the button is clicked. This script will gather the necessary values from the current record and build the URL parameters for the Suitelet. Here is a sample code snippet:
Copy code
javascript
function createQuoteForm() {
    var currentRecObj = currentRecordMod.get();
    var caseId = currentRecObj.id;
    var suiteletUrl = url.resolveScript({
        scriptId: 'customscript_your_suitelet_script_id',
        deploymentId: 'customdeploy_your_suitelet_deployment_id',
        params: {caseId: caseId}
    });
    window.open(suiteletUrl);
}
return {createQuoteForm: createQuoteForm};
3. Create a Suitelet that will create the quote record. This Suitelet will be triggered in the background when the button is clicked. Here is a sample code snippet:
Copy code
javascript
function onRequest(context) {
    var caseId = context.request.parameters.caseId;
    var caseRecord = record.load({
        type: record.Type.SUPPORT_CASE,
        id: caseId
    });
    var quoteRecord = record.create({
        type: record.Type.ESTIMATE,
        isDynamic: true
    });
    // Set fields on quote
    quoteRecord.setValue({
        fieldId: 'entity',
        value: caseRecord.getValue({fieldId: 'company'})
    });
    // Add more fields as needed
    // Save the quote record
    var quoteId = quoteRecord.save();
}
return {onRequest: onRequest};
Remember to replace the script and deployment IDs with your actual Suitelet's script and deployment IDs. Also, replace the field IDs and record types with the actual IDs and types you are using in your account. ****** 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.853458405
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847281873
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846071362
Please provide your feedback on this answer.