I'm working on my first Suitelet -> (clientscri...
# suitescript
m
I'm working on my first Suitelet -> (clientscript) -> Suitelet program and I can get the Suitelet to run properly , but once I started trying to pass the parameters, everything just... stops. The concept is 2 fields in Suitelet A, passing into a PageInit Client Script, then using those as filter variables on Suitelet B. Here are what I THINK are the relevant code blocks: SUITELET A (form/button):
Copy code
form.addSubmitButton({
            id: 'custpage_openform',
            label: 'Submit',
            functionName: 'openSuitelet'
        });
        form.clientScriptModulePath = 'SuiteScripts/Suitelets/cs_fulfill_delete_param.js';
            log.debug({title:'CS Script ID', details: form.clientScriptModulePath });

        context.response.writePage(form);
        }
    return {
        onRequest: onRequest
    };
});
CLIENT: Using N/currentRecord, N/url, and N/https
Copy code
function pageInit(context) { };

function openSuitelet(context) {
    var currentRecObj = currentRecord.get();
        log.debug({ title: 'Current Record Get', details: "This function was called"});

    var warehouse = currentRecObj.getValue({
        fieldId: 'custpage_warehouse'
    });
    var admincode = currentRecObj.getValue({
        fieldId: 'custpage_admincode'
    });

    var suiteletURL = url.resolveScript({
        scriptId: 'customscript_br_sl_fulfill_dele_execute',
        deploymentId: 'customdeploy_br_sl_fulfill_dele_execute',
        returnExternalUrl: true,
        params: {
            warehouse: warehouse,
            admincode: admincode
        }
    });
}
return {
    pageInit: pageInit,
    openSuitelet: openSuitelet
};
SUITELET B (Search)
Copy code
function onRequest(context) {
    var form = serverWidget.createForm({
        title : 'Item Fulfillments to be Deleted'
    });
    if(context.request.method == 'GET'){

        var requestparam = context.request.parameters;
        var warehouse = requestparam.warehouse;
        var admincode = requestparam.admincode;

       var fulfillSearch = search.create({  //etc...
I think I've stumbled onto one part, which is in the Suitelet B, having the parameters in the script record (forgot that). But if so, so I call/use the internal IDs for those (e.g. warehouse : custparam_warehouse) in the search filter? Still a rookie at this stuff-I know enough to be dangerous, but this is my first multi script project and I know I'm missing something easy.
s
These don't actually need to be 2 suitelets. You can set a parameter in the client script when you call the suitelet, and just have 2 form rendering functions in the same script file.
You don't need parameters in the script record
Actually I don't see why you need your client script at all to achieve this.
Copy code
if (context.request.method == 'GET') {
            // render initial form
            // add a submit button (that will take you to page 2)
            context.response.writePage(form);
        } else {
          // check for the 2 parameters you are looking for with context.request.paramaters
          // if they exist, render page 2

          // else (assuming there is some action they can take from page 2) handle POST from page 2
        }
m
The 2nd Suitelet actually uses the search to target transactions for deletion - it loads a sublist with the markall and checkboxes and then on submit deletes those transactions.
So I thought I would need a 2nd one.
n
Are you doing anything with
suiteletURL
after you resolve the url?
@Mark C ā˜ļø
m
Um... No. I'm going to feel really dumb for asking, but I couldn't find anywhere to use it from code samples doing 'similar' things.
n
@Mark C so resolving the script will give you the URL, but you have to tell the browser to navigate to it
right now it looks like you're assigning the url to
suiteletURL
and the method exits, so I wouldn't expect anything to happen when you click the button
m
oh. my. god. derpy derp.
n
if you added something like window.location.replace(suiteletURL) it would redirect
m
Off to Webstorm! Thanks! (feeling šŸ‘ish and grateful)
n
Sandii is right that you could use 1 suitelet to accomplish it as well. You'd just use a parameter to route to the correct render function
something like this:
Copy code
function onRequest(context) {
        const {
            method,
            parameters: {
                transid,
                chgtype,
                ocrid,
            },
        } = context.request;
        const isNew = !nsutil.isEmpty(transid) && !nsutil.isEmpty(chgtype);
        const isView = !nsutil.isEmpty(ocrid);

        if (method === 'GET') {
            if (isNew || isView) {
                return renderForm(context);
            }
            renderList(context);
        } else if (method === 'POST') {
            return handleForm(context);
        }
    }
m
I actually started combining them in a new script - I'll play w/ that and see if I can make it sing. Thanks so much to you both!
I've tried, but I'm not experienced enough to combine them at this point. I'm a lot closer, but still trying to figure out a few things about calling the Client Script from the Suitelet. Warning: Uber-rookie questions ahead! • The samples I've seen around NetSuite and the Internet all seem to suggest that the client script is loaded in the file cabinet without a script record or deployment (since it's not tied to a record type) ā—¦ None of them have a pageInit, saveRecord, etc. function, but when I try to upload the .js without one, I'm blocked. • I assume that I need pageInit, and the button calls the other function w/i the client script. • Finally, if I can actually get the client to do what it's told, have I solved the URL open the suitelet (in the next message in thread)? ā—¦ Related, should there be quotes around the first parameter name? I've now seen it both ways in examples. Thanks - I'm learning, but this is a much-needed tool, and it's just out of my reach.
Copy code
var suiteletURL = url.resolveScript({
    scriptId: 'customscript_br_sl_fulfill_dele_execute',
    deploymentId: 'customdeploy_br_sl_fulfill_dele_execute',
    returnExternalUrl: false,
    params: { 'warehouse': warehouse,'admincode': admincode }
});
window.onbeforeunload = null;
location.href = suiteletURL;
b
a script file that has been used as the script file for a client script needs to pass the rules for client script validation
make a new file if you just want to use for your button
šŸ‘ 1
I usually recommend using window.open to open a new tab/window
using location.href will change the url of the current tab/window
learn how Objects and properties work
so that you know when quotes around keys are optional, and when they are mandatory
modern code editors tend to have linting options that tell you when you are using quotes when they are optional
m
I'm getting used to WebStorm - it's been a great way to catch my errs. Quotes, commas, brackets, etc. I am seeing WAY fewer problems than I was a few weeks ago - so I'm learning something! But I'll definitely look through the objects link - thanks!