Hey all, i'm having trouble finding an answer on t...
# suitescript
c
Hey all, i'm having trouble finding an answer on this one: I have a suitelet that renders a list and I have a client script that I wanted to use for DOM manipulation, but I cannot get the client script to run. Specifically, the pageInit function won't trigger. The client script has a script record attached, but no deployment. I found a post with this almost exact same issue from a few years ago with no resolution. Is this a known issue? Here's the code: Suitelet:
e
You need form.clientScriptModulePath to reference the client script if you want it to run with your Suitelet
c
Even if there is no form in my suitelet?
The suitelet's only pageObject is a list, not a form, so i'm using list.clientScriptFileId instead of the form.clientScriptFileId
s
I would try changing the file id to a string
c
While that wouldn't surprise me, it didn't work 😞
s
I would try using clientScriptModulePath instead of id, I never use fileId
c
Tried that one as well with similar results. I tried moving the assignment up towards the top of the function that creates the list, but still haven't gotten it to trigger. This ones got me banging my head against the wall
e
Try adding this at the top after @ScriptType - @NModuleScope SameAccount
c
Good catch, no luck though still 😞. tried switching back to modulePath instead of fileId for good measure again and still nada
e
Have you tried creating a form and then using the form.clientScriptModulePath vs the list one even if you don’t need the form?
s
I basically never use just list type but why would want/need a client script on a page that is just a list? You cannot interact with a list afaik?
c
I wanted to use it to manipulate the DOM to highlight certain rows of the list, and to add an input for one column (similar to a sublist). The search I use to populate this list returns hundreds of rows and sublists don't handle that many lines well. I was hoping I could hack together a list for better performance instead. I was surprised to see there was even an option to include a client script on lists. As you pointed out, there really isn't much to interact with in the first place, atleast within netsuite's recommendations.
s
Oddly enough, I found a file that I made that only returns a list and has a client script module path, and it works fine
πŸ‘ 1
πŸ€” 1
c
And your client script is using the pageInit entry point?
This may be one of those situations where I wind up rewriting everything and it miraculously works. 😑
s
Copy code
exports.onRequest = function onRequest(context) {
        if (context.request.method == 'GET') {
            //var form = renderForm(context);
            var list = renderList(context);
            context.response.writePage(list);
        } else { }
    }
    function renderList(context) {
        var list = serverWidget.createList({
            title: 'Additional Locations',
            hideNavBar: true
        });
        var itemId = context.request.parameters.itemId;
        var networkViewData = getDataForList(itemId);
        buildList(list, networkViewData);
        list.clientScriptModulePath = './lib/networkview_jquery';
        return list;
    }
πŸ‘€ 1
Copy code
/**
 * @NModuleScope public
 * @NApiVersion 2.x
 */
var length = jQuery(jQuery('#div__bodytab')[0].children[0].children).length;
for (var index = 0; index < length; index++) {
    var rowId = jQuery(jQuery('#div__bodytab')[0].children[0].children)[index].id;
    if (rowId) {
        rowId = '#' + rowId;
        var textContent = jQuery(jQuery(rowId)[0].children[1])[0].textContent;
        textContent = textContent.trim();
        switch (textContent) {
            case '1-Critical':
                colorLine(rowId, '#D69292');
                break;
            case '2-High':
                colorLine(rowId, '#FFD9DD');
                break;
            case '3-Medium':
                colorLine(rowId, '#F8FAD9');
                break;
            case '4-Low':
                colorLine(rowId, '#E6FFE8');
                break;
            case '5-OToG':
                colorLine(rowId, '#E8EBFA');
                break;
            default:
                break;
        }
    }
}
function colorLine(rowId, color) {
    var rowChildren = jQuery(rowId).children();
    for (var i = 0; i < rowChildren.length; i++) {
        rowChildren[Number(i)].style.setProperty('background-color', color, 'important');
    }
}
πŸ‘€ 1
client script is just coloring lines
m
I usually do this in the suitelet end with html tags in the list fields
πŸ‘ 1
b
minor warning, the client script for list pages is for the buttons
use a form if you want entry points in your client script
πŸ‘ 1
c
Thanks all! Removing the entry point and script record for the client script seemed to fix it. I learned a client script without an entry point will run on load for suitelets.