0

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'
};
WTP API
  • 546
  • 3
  • 16
  • Sorry but I'm a bit confused here. Can you tell me your expected input and output for your provided code snippet. What is my understanding is, you want to concat the Opportunity status with a static string ; am I right ? – Rockstar Sep 16 '15 at 04:58

2 Answers2

2

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.

prasun
  • 7,073
  • 9
  • 41
  • 59
  • This is dead on. It's not a concatenation issue but rather a scope issue. The variable right now is declared outside of the function you are trying to use it in. That's why this answer works – TMann Sep 16 '15 at 12:53
  • Thanks everyone for their input. This worked for me, but the value came as "null" for the oppStatus () function. I probably referenced the incorrect field name in NetSuite. I can research this. Thanks again!!! – WTP API Sep 30 '15 at 20:46
0

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);
    }   
}
Nick
  • 37
  • 4