Hey everyone - New here! Great to meet you all I a...
# suitescript
h
Hey everyone - New here! Great to meet you all I am working on a bundle of Scripts (Client, User Event, and Suitelet) in the hopes of getting a custom button to populate onto the Sales Order on view/before record load - When they click the button 'Print Commercial Invoice' then it populates a PDF of the custom Commercial Invoice to be sent with the inventory. I have created a custom Sales Order template and attached it inside of the Suitelet and they all are saving without issues/warnings. All 3 scripts are under the File Cabinet: SuiteScripts and the User Script has the Client Script ID embedded. When the deployment is in Testing/Debug it lets me see the Sales Order Form however when the deployment is Released/Debug it states that there is an unexpected error that has occurred - I am thinking it has something to do with the Client script but I can't put my finger on what exactly could be causing it. I have attached the 3 scripts below - If someone could point me in the right direction that would be awesome. Thanks in advance everyone!
a
what error are you getting and when are you getting it?
Copy code
form.clientScriptModulePath = 'customscript1666'; // Path to your client script file
this is not a path to your client script
it should be in the form
Copy code
form.clientScriptModulePath ='SuiteScripts/TSOL - Commercial User.js';
AI code? 🙂
☝️ 2
h
First time for everything and i got this put into my lap - Usually would just create a custom form and attach it via the Linked Forms but the field is being used by another custom form.
Originally i attempted with "form.clientScriptModulePath ='SuiteScripts/TSOL - Commercial User.js';" but it has been giving me the same issue.
I just keep getting this
a
Don’t publish your Account ID…
h
sorry about that - unaware it was a rule
a
No rule, security recommendation for you…
👍 2
h
image.png
a
ok useless error message... and when do you get that? when you try to load your SO?
h
yes sir - when its in testing mode it populates the SO but when its in release mode its giving me this
a
script permissions
on your UE script deployment
in testing mode it will always run for the logged in user
h
Its in release/debug and i changed the Role from current role to Admin which got me past the error but now my pop-up isnt coming up on the SO. Since this is all scripted, I wouldnt need to do the Linked Forms if i understand correctly and it should populate within the SO via hardcoding. Am i missing something in my understanding?
a
okay... i lied about the path it needs to be relative, your UE script is in the same folder right? so you need a dot not SuiteScripts
Copy code
form.clientScriptModulePath ='./TSOL - Commercial User.js';
h
ok ill test this out real quick - thanks
that saved without issues but i dont see any changes to it not popping up on the SO.
a
so no on screen errors... but no functionality either? 🙂
h
yes sir
a
you have debug with your logs - what code is being executed and what code isnt
so your SO loads.. the button is there.. but clicking it does nothing?
h
i reviewed the execution log on the script deployment and nothing was logged. When i also look at the sales order workflow history that allowed me through and nothing was logged on there as well
a
umm you have 3 scripts and 3 script deployments hopefully? do they all not have any logs?
I assume at this point that the UE is doing what it needs to do correctly, so we need to determine if its the suitelet or the client script that are failing
h
I only deployed the Suitelet - is it required to deploy all scripts even though i am not utilizing the other 2 deployments in this?
a
umm... what?
if the CS is only running in view mode then you may not need a script record or deployment for that, its just attached to your UE, cant remember off the top of my head i may have this backwards
but both the UE and suitelet will 100% always need both a script and a deployment
if your button is showing up on the SO form then you DO have that UE deployed
👍 1
h
ok i understand - ill have to go and deploy the UE bc i was under the awareness that the Suitelet would be the only one needed to deploy as the Script ID and the deployment ID for the CS
a
if you want scripts to run you need to deploy them is the general rule 🙂
🤭 1
h
so the Suitelet and UE are now live but im still not getting the pop up so i am also going to deploy the CS as well.
All 3 have been deployed but the result is still the same
a
ok but logs?
h
no sir - its not showing me anything
image.png,image.png,image.png
a
and if you open the devtools by pressing F12 on the SO page? do you see anything when you click the button in the console area?
you need to set the logging level to debug
👍 1
h
this is what i see in the Console area
a
gothca... none of that is relevent and if you click the button does anything else appear
h
i changed them all back to debug and havent seen the button to click
a
wait what? the button isn't showing up ? sorry I thought you'd confirmed that already
h
no sir its not populating. This is what the test SO looks like after save
a
ok show screenshot the audience tab on the UE deployment
h
image.png
a
you need to check the box that says all internal roles
or all employees, i think both would work fine
this is what i mean about 45 mins ago when I said "permissions"
h
i clicked the internal roles but it then gave me that unexpected error on the SO
a
ok share whatever the UE js is currently
the script is clearly broken
h
TSOL - Commercial User.js
a
you weren't getting an error cos the script wasn't executing, now its executing its giving the error
...okay, kind of a weird one but i think the combination of including the serverWidget module and use a variable named
form
might be your issue... I've just renamed the form variable to be thisForm instead and removed the commented out stuff that was just noise
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/ui/serverWidget', 'N/log'], (serverWidget, log) => {

/**
 * Before Load event - adds the Commercial Invoice button
 * @param {Object} context - Script context
 */
const beforeLoad = (context) => {
try {
    log.debug('User Event Script', 'Starting beforeLoad');

    // Only add button on VIEW mode
    if (context.type !== context.UserEventType.VIEW) {
        log.debug('User Event beforeLoad', 'Not VIEW mode, exiting');
        return;
    }

    const thisForm = context.form;
    const salesOrderId = context.newRecord.id;
    log.debug('User Event beforeLoad', 'Processing Sales Order ID: ' + salesOrderId);

    // Attach the client script to the form
    thisForm.clientScriptModulePath = './TSOL - Commercial Client.js'; // Path to your client script file
    // Add the Commercial Invoice button
    thisForm.addButton({
        id: 'custpage_print_commercial_invoice',
        label: 'Print Commercial Invoice',
        functionName: 'printCommercialInvoice'  // This calls the client script function
    });
    log.debug('User Event beforeLoad', 'Commercial Invoice button added successfully');
    } catch (error) {
        log.error('User Event beforeLoad Error', {
            message: error.message,
            stack: error.stack
        });

    }
};

    return {
        beforeLoad
    };
});
if the SO isn't loading or the button isn't showing we don't need to worry about the suitelet or the client script, the UE isn't working
t
It sounds like the issue is with the user event script, but it may be worth a try to remove the @NScriptType ClientScript tag in the client script. Since the client script is being attached it doesn’t need this tag and I’ve had that cause issues when adding custom buttons like this. It also shouldn’t need to be deployed, just loaded in the file cabinet