admin管理员组

文章数量:1318335

I am unable to set a field of type INLINEHTML using SuiteScript 2.0. However, the same field works with SuiteScript 1.0. Here is the code snippet:

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
// In SuiteScript 2.0   
define(['N/search'], function(search) {
    return {
        pageInit: function(context) {
            var currentRecord = context.currentRecord;
            // Set Value (This does not set any data)
            currentRecord.setValue({ fieldId: 'inline_html_field', value: '<div>Test Value</div>' });
            // Get value (Returns undefined)
            currentRecord.getValue({ fieldId: 'inline_html_field'});
        }
    }
});

// In SuiteScript 1.0
nlapiGetFieldValue('inline_html_field'); // Returns the data in field

I am unable to set a field of type INLINEHTML using SuiteScript 2.0. However, the same field works with SuiteScript 1.0. Here is the code snippet:

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
// In SuiteScript 2.0   
define(['N/search'], function(search) {
    return {
        pageInit: function(context) {
            var currentRecord = context.currentRecord;
            // Set Value (This does not set any data)
            currentRecord.setValue({ fieldId: 'inline_html_field', value: '<div>Test Value</div>' });
            // Get value (Returns undefined)
            currentRecord.getValue({ fieldId: 'inline_html_field'});
        }
    }
});

// In SuiteScript 1.0
nlapiGetFieldValue('inline_html_field'); // Returns the data in field
Share Improve this question asked Aug 29, 2017 at 7:50 tarunbandiltarunbandil 611 silver badge6 bronze badges 2
  • Are you creating this field dynamically or is it a custom field that lives on the record? – Todd Grimm Commented Aug 31, 2017 at 17:19
  • It's custom field that is available on record. – tarunbandil Commented Sep 1, 2017 at 6:14
Add a ment  | 

6 Answers 6

Reset to default 1

Unfortunately this is an instance where the logic implemented behind the record.getValue() or the currentRecord.getValue() in SS 2.0 is flawed. In SS 1.0 a nlapiGetFieldValue() passes through less validation than the SS 2.0 counterpart. Here is an example (hopefully changed enough that NetSuite doesn't throw me in jail for violating their IP). This is what is happening when you request the value.

function getTheValue(options)
        {
            var fieldId;

            fieldId = '....';// Do a bunch of logic to validate the options parameter is correct

            return doGetTheValue(fieldId);
        }

        function doGetTheValue(fieldId)
        {
            var fieldObj = goodOlegetField(fieldId); // goodOle being our 1.0 api prefix....
            // the function call above returns null preventing your request from succeeding.
            var value;
            if (fieldObj == null)
                return undefined;


        }

I hope this makes sense, and although it isnt an answer it will provide insight as to why you are getting the response you are getting. Its also solid validation that you are not crazy. I have frequently found I need this reassurance when working with SS 2.0.

I had similar issue, you need to use suitescript 1.0 to manipulate inline html field in NetSuite. However, instead of transforming the whole code from suitescript 2.0 to 1.0, you could use this:

window.nlapiSetFieldValue('YOUR_FIELDID', '<a>YOUR HTML CONTENT</a>');

By putting window. you could use any suitescript 1.0 api in suitescript 2.0!

I think you need the currentRecord module.

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
// In SuiteScript 2.0   
define(['N/search', 'N/currentRecord'], function(search, currentRecord) {
    return {
        pageInit: function(context) {
            var currentRecord = context.currentRecord;
            // Set Value (This does not set any data)
            currentRecord.setValue({ fieldId: 'inline_html_field', value: '<div>Test Value</div>' });
            // Get value (Returns undefined)
            currentRecord.getValue({ fieldId: 'inline_html_field'});
        }
    }
});

When dealing with inline html fields I just treat them as normal html on the client side. To avoid issues I'll generally have a default value

// User Event Before Load
nlapiSetFieldValue('custbody_inline_field', '<div id="myuniqueid">default content</div>');

or

var fld = form.addField('custpage_inline_field'...); // look up field creation in the help.
fld.setDefaultValue('<div id="myuniqueid">default content</div>');

and then on the client just manipulate the content of $("#myuniqueid"). You don't have to use jQuery but it's included in the NS GUI now.

Use this it may help:

var val = currentRecord.getValue({ fieldId: 'inline_html_field'});
log.debug({title:test,details:JSON.stringify(val);})

Recently, I try to set a field of type INLINEHTML using UserEvent ScriptType, that can work. ClientScript only can work when editing the record.

本文标签: javascriptSetting inline HTML field from Client Script in SuiteScript 20Stack Overflow