Setting inline HTML field from Client Script in SuiteScript 2.0

7.2k views Asked by At

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
6

There are 6 answers

2
user3075978 On

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'});
        }
    }
});
0
bknights On

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.

0
Todd Grimm On

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.

0
Pushpak Gupta On

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!

0
tong zou On

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

0
Narendra Reddy Sathi On

Use this it may help:

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