I have a Client Script I created. - Script is load...
# suitescript
r
I have a Client Script I created. • Script is loaded in NS, with
pageInit
&
validatefield
entry points. • Script is deployed to a custom record in NS to all Roles • Both Script record & Deployment record are both in Testing/Debug mode, • Scripted Records shows the client script being attached to the custom record However when I load the custom record, the
pageInit
function is not firing and for the life of me I cannot figure out why. Does anyone know some pitfalls I can check to figure out why it's not firing?
e
Does it run in all events (Create, Edit) and Contexts (UI)? Are you logging the
pageInit
?
r
I have "Event Type" on deployment as blank, which as far as I understand means it runs it in all contexts. The pageInit currently just consists of
Copy code
const pageInit = (scriptContext) => {
        console.log('foo');
        alert('foo');
        Nlog.debug({
            title: 'pageInit',
            details: 'pageInit'
        });
}
b
what does the script record and script deployment records look like
r
also tried in an inprivate window as well just to make sure it wasn't some weird caching issue, but still no go
b
script and script deployment look normal
the only thing you really need to watch out for is that the script will only run if you are logged in as the owner
what does the rest of the code look like
r
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 * @author Rick Goodrow <rickg@unikavaev.com>
 */
define([
    'N/record',
    'N/ui/message',
    'N/ui/dialog',
    'N/log',
    'SuiteScripts/unika_vaev/lib/uv_lib_id',
    'SuiteScripts/unika_vaev/lib/uv_lib_common_client',
    'SuiteScripts/unika_vaev/hni_shipments/uv_lib_hni_shipment',
],
/**
 * @param {record} Nrecord
 * @param {message} NuiMessage
 * @param {dialog} NuiDialog
 * @param {log} Nlog
 * @param {object} uv_lib_id
 * @param {object} uv_lib_common_client
 */
function(Nrecord, NuiMessage, NuiDialog, Nlog, uv_lib_id, uv_lib_common_client) {

    let linkedFulfillmentsOriginalValue = null;

    /**
     * Function to be executed after page is initialized.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
     *
     * @since 2015.2
     */
    const pageInit = (scriptContext) => {
        console.log('foo');
        alert('foo');
        Nlog.debug({
            title: 'pageInit',
            details: 'pageInit'
        });
        // uv_lib_common_client.addStyleSheets();
        // Nlog.debug({
        //     title: 'styleSheetsAdded',
        //     details: 'styleSheetsAdded'
        // });
        // uv_lib_common_client.updateState();

        // set placeholder value on page init so we know what value to fall back to
        // linkedFulfillmentsOriginalValue = scriptContext.currentRecord.getValue({
        //     fieldId: uv_lib_hni_shipment.ref.record.HNI_SHIPMENT.field.SHIPMENT_FULFILLMENTS,
        // });

    }

    return {
        pageInit: pageInit,
    };
    
});
r
Client scripts only work on Edit mode, not sure that is what you meant by
when I load the custom record
. You might be loading it in view mode.
r
@rustyshackles that was the missing info I was looking for. I was trying to do some DOM manipulation (I know it's officially unsupported). Is there any way to do DOM changes when Viewing a record? UserEvent beforeLoad fires before page is rendered
r
The approach I usually take is, beforeLoad script that adds a inlinehtml field, then put the dom manipulation code in that field
b
use Form.clientScriptModulePath to add a script to the page
r
would that allow the script to run on view mode? I just assumed since it says
clientScript
it would only execute on edit mode
r
@rustyshackles my eye is twitching at the inlineHtml approach, but I know NetSuite has it's quirks. Is there any limit to the number of characters I could put in an inlineHtml field that would limit the amount of DOM manipulation I can do?
and using the clientScriptModulePath, can I pass any parameters to that file, or would it be static only?
r
@Rick Goodrow That I do not know, I seldom do DOM manipulation
👍 1
r
@rustyshackles thanks for this tip. I have abstracted it out for my needs (adding custom state label to any custom record)