I feel like I am doing something wrong here. I was...
# suitescript
k
I feel like I am doing something wrong here. I was able to get the button to appear but the client script is not executing
Copy code
[3:03 PM] const beforeLoad = (scriptContext) => {
    try {
        // only run in view mode
        // if (scriptContext.type !== scriptContext.UserEventType.VIEW) return;

        // get form and record then attach our client script to the form. This will ensure that the button click action
        // will run our client script function.

        const { form, newRecord } = scriptContext;





        const recCurrent = scriptContext.newRecord;
        const objForm = scriptContext.form;
        const stStatus = recCurrent.getValue({
            fieldId: 'status'
        });

        const stSuiteletLinkParam = runtime.getCurrentScript().getParameter({
            name: 'custscript2'
        });

        // attach client script to form.
        objForm.clientScriptModulePath = "./OpenSuiteClientScript.js";

        //const suiteletURL = '\"' + stSuiteletLinkParam + '\"';
        if (stStatus === 'Pending Fulfillment') {
            //     objForm.addButton({
            //         id: 'custpage_suiteletbutton',
            //         label: 'Print CompN',
            //         functionName : 'window.open(' + suiteletURL + ')',
            //     });
            // }

            // create button, give it a name, and assign it the function we will write in our client script
            // When the button is clicked, it will run the function we assign to it.
            const printButton = form.addButton({
                id: "custpage_custom_button1",
                label: "Something",
                functionName: "callSuitlet",
            });
        }

    } catch (e) {
        log.error({ title: "Error in beforeLoad", details: e });
    }

}
[3:06 PM] I tried to log out the stSuiteLinkParam but I didnt get anything [3:06 PM] log.debug("suitelink", stSuiteLinkParam)
r
if you don't have a script record and a deployment on your client script, you want to use console.log and open your browser console to see the log.
k
@reptar I have the client script deployed on the sales record and the client script wont fire at all.
I have the right file name
o....its inside of a folder
😂 1
r
happens
you don't need the script record and deployment record for this use case
👍🏻 1
if you're comfortable debugging in the console
k
I was able to get the buttons to appear but when clicked the client script won't fire my custom function @reptar
Copy code
function pageInit(scriptContext) {
    function callSuitlet() {
        try {
            log.debug("this is firing", suiteletUrl);

            // call the suitelet
            const suiteletUrl = url.resolveScript({
                scriptId: "customscript1197",
                params: {},
                returnExternalUrl: false,
            });


            // load the suitelet in the browser
            window.open("<https://www.google.com>");
        } catch (e) {
            log.error({ title: "error in callSuitelet", details: e });
        }
    }
}
r
entry point needs to be separate from
pageInit
, and returned like any other entry point function.
👍 1
k
ok cool
👍 1
n
Usual pattern is : 1. UE Script before load add button to form 2. Same UE Script before Load specify the path to the client script with the function(s) in it. You do not need to deploy the client script if that's all the client script is doing, i.e. providing button function functionality.