简体   繁体   中英

With SuiteScript, how to combine JavaScript variables in a string?

I apologize in advance, I am very new to JavaScript and NetSuite.

I'm utilizing the DocuSign for NetSuite bundle. The bundle has options to use their functions within a button.

PROBLEM: I'm attempting to take a field value from NetSuite and combine it into a custom email subject field. For example, Opportunity Status.

Is this supported by SuiteScript? If so, how?

JavaScript in general seems to support it by using the syntax of "This is dynamic + 'customVariableName'."

Below is my script and thanks in advance:

function oppStatus () {
var status = nlapiGetFieldText('status');
}

function customSendMain () {
var searches = [
{ keyword: '.docx .doc'
, type: 'broad' }
];
var staticEmail = {
subject: 'Opportunity ' + status,
blurb: 'Static email blurb'
};
var recipients = docusignGetRecipients(docusignContext);
var files = docusignGetFiles(docusignContext, searches);
var email = staticEmail;
return docusignPopulateEnvelope(docusignContext, recipients, files, email);
}

"email" within the "docusignPopulateEnvelope" is an object. "subject" and "blurb" contain string values.

How can I reference a variables value within the string for either "subject" OR "blurb"? I keep getting syntax errors.

Also tried it like this:

var staticEmail = {
subject: Opportunity ' ' .status,
blurb: 'Static email blurb'
};

This appears more to be a JS syntax than Suitescript sepcific.

If you want to access variable "status", you can modify code as:

function oppStatus () {
return nlapiGetFieldText('status'); 
}

var staticEmail = {
subject: 'Opportunity ' + oppStatus(),
blurb: 'Static email blurb'
};

If this is what you mean to ask.

Worked by using below.

function RecipientsMain() {
    var recordId = docusignContext.recordId;
    var contactId = nlapiLookupField(docusignContext.recordType, docusignContext.recordId, 'customField');
    if(contactId != '')
    {   
        var fields = ['entityid', 'email'];
        var contactFields = nlapiLookupField('contact', contactId, fields);
        var entityName = contactFields.entityid;
        var entityEmail = contactFields.email;
        var dummyRecipients = [
            { id: 1 
            , order: 1
            , name: entityName
            , email: entityEmail

        }];
        var nsRecipients = docusignGetRecipients(docusignContext, 2, 2);
        var recipients = dummyRecipients.concat(nsRecipients);
        var files = docusignGetFiles(docusignContext);
        return docusignPopulateEnvelope(docusignContext, recipients, files);
    }
    else
    {
        var files = docusignGetFiles(docusignContext);
        var recipients = docusignGetRecipients(docusignContext);
        return docusignPopulateEnvelope(docusignContext, recipients, files);
    }   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM