Hello, I made a Client script which retrieves the ...
# suitescript
i
Hello, I made a Client script which retrieves the GPS coordinates of a user when he presses the "Arrived" button contained in a User event script which calls him the function contained in the client script. This was working well. But I wanted to call these scripts in a workflow by creating a Suitelet launched by the client script to advance the workflow action. But when I try to import the client script on NetSuite I have the following error:
Error
Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"{stack=[Ljava.lang.Object;@41320eed, toJSON=org.mozilla.javascript.InterpretedFunction@3c5d36f5, name=MODULE_DOES_NOT_EXIST, toString=org.mozilla.javascript.InterpretedFunction@3748319, id=, message=Module does not exist: N/redirect.js, TYPE=error.SuiteScriptModuleLoaderError}","message":"","stack":[]}
Is it due to the redirection module that I added in the
gpspositionButtonUser()
function of my client script? I put here the client script and the suitlet script.
m
Hi, the N/redirect module is not supported for Client Scripts
“Suitelets, beforeLoad user events, and synchronous afterSubmit user events are supported”
i
Ok. Please can you correct the script with this logic to call back the suitlet in the client script?
Indeed, I do not quite understand the approach that you are giving me here.
Do you mean to call the client script in the beforeLoad function of my user event script and the suitlet in the afterSubmit function of the same script?
Finally I removed the redirect in the client script and put it in the script user event in the afterSubmit function. Below is the code of the user event script.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
 define(['N/record','N/redirect'], function (nCurrentRecord,nRedirect) {
    function beforeLoad_addButton(scriptContext) {
        var form = scriptContext.form;

        form.addButton({
            id : 'custpage_gpsuserbutton',
            label : 'Arrivé',
            functionName : 'gpspositionButtonUser()'
            //GpspositionButtonUser est la fonction exécuté pour capture la position GPS de l'utilisateur
        });


        form.clientScriptFileId = 223; //ceci est l'id de mon client script dans le file cabinet
    }

    function afterSubmit(scriptContext) {
        nRedirect.toSuitelet({
            scriptId: 224,                           
            deploymentId: 1,                          
            parameters: {
                'soid': nCurrentRecord.get().id
            }
        })

    }
    return {
        beforeLoad: beforeLoad_addButton,
        afterSubmit:afterSubmit
    }
});
But when I run my workflow I get this error
*Notice (SuiteScript)* {"type":"error.SuiteScriptError","name":"InternalError","message":"missing ; before statement","stack":["createError(N/error)","beforeLoad_addButton(/SuiteScripts/event_buttonpositiongps.js:18)","createError(N/error)"],"cause":{"message":"missing ; before statement","fileName":"","lineNumber":1,"name":"InternalError","stack":"\tat /SuiteScripts/event_buttonpositiongps.js:18 (beforeLoad_addButton)\n\tat INVOCATION_WRAPPER$sys:26\n\tat INVOCATION_WRAPPER$sys:17\n\tat INVOCATION_WRAPPER$sys:34\n\tat INVOCATION_WRAPPER$sys:1\n","rhinoException":"org.mozilla.javascript.EvaluatorException: missing ; before statement"},"notifyOff":false,"userFacing":true}
Any idea please?
b
what is your workflow for, it cant possibly be making this chain of scripts any easier
i
In fact, I want to be able to retrieve the GPS position, as well as the current date and time of the user when he clicks the button
b
none of that sounds like things you would want a workflow or even a suitelet
its sounds like pure client script