Given the following Suitelet code: ```/** * @NApi...
# suitescript
n
Given the following Suitelet code:
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(["N/search", "N/render", "N/record"], function (search, render, record) {
    "use strict";

    function onRequest(context) {
        log.debug("Hello", "World");
        if (context) {
            log.debug("context", "exists");
        }
        if (context.request) {
            log.debug("context.request", context.request);
        }
    }

    return {
        onRequest: onRequest,
    };
});
Why do I get the error: "error": { "code": "JS_EXCEPTION", "message": "org.mozilla.javascript.EcmaError: TypeError: Expected argument of type object, but instead had type string (/SuiteScripts/script.js#14)" } Thread in Slack Conversation
I think I'm missing something super obvious.
c
N/log
Specifically, log.debug, unless it has an undocumented overload that accepts two string parameters instead of an options object
e
Unrelated: Why do I so frequently see people using
use strict
in SuiteScript? What does it change about the NetSuite runtime? Is this a holdover from the browser? What am I missing?
All the log methods have that overload. It's not clear to me why you'd see this error.
šŸ‘ 1
n
I've tried,
Copy code
function onRequest(context) {
  log.debug("Hello", "World");
  if (context) {
    log.debug("context", "exists");
    log.debug({ 
      title: "context", 
      details: JSON.stringify(context)
    });
  }
}
e
No need to stringify in that example
The log methods do that for you
n
It logs the "Hello World" and "context", "exists"
e
Though it shouldn't cause a problem to do so
c
Looks like the error is coming from line 14, which is the only line that passes an object to the log function as the second argument
Copy code
log.debug("context.request", context.request);
e
No error doing so client-side
c
What does calling log like that from the browser do? šŸ¤”
e
Nor server-side in a Suitelet I have
šŸ™Œ 1
It doesn't do anything other than invoke the log methods
šŸ‘ 1
c
Maybe it's an effect of "use strict"
n
ah, So I've hit the Suitelet endpoint using the browser, logs fine. no errors. If I hit the endpoint using postman, logs error.
e
odd
n
probably less about the log.debug and more about the context I suspect, thanks for the help
c
Are the browser and postman requests using different URLs / auth?
a
I think the problem is that
details
is overloaded but
title
is not, therefore trying to use
context
which is an object in the
title
is what is causing this problem.
e
Which line uses an object in the
title
?
a
log.debug({ title: "context", details: JSON.stringify(context) });
if (context) { log.debug("context", "exists"); } if (context.request) { log.debug("context.request", context.request); }
e
Those first params are all strings
You can peruse the source of the
log
module on the client side. This is how the overload works:
a
I totally missed the
""
you are right @erictgrubaugh Then it must be this:
"use strict";
n
I'll try without
"use strict"
More of the same, Chrome browser works, Postman throws the error.
c
@nathanw Are the browser and postman requests using different URLs and/or auth?
n
@Clay Roper Same Url, Postman using TBA
c
@nathanw Are they both authenticating as the same user and role?
s
the two-string parameter is not documented is it
e
It is not
n
@Clay Roper, same user different Role
@Clay Roper, let me try same user / same role
c
@nathanw Nice - I'm not sure why it would matter, but it helps to reduce the variables šŸ˜„
n
good call, I've run in both chrome / postman as same user / same role • chrome - works, logs context • postman - throws error
a
Since you are using Postman, I assume you are using a Suitelet Available without login, there are some shenanigans with those, as you can see here: • https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_N2997713.html With that being said, please try to set a User-Agent in Postman.
n
@alien4u The Suitelet is not available without login
a
If the Suitelet is not available without login I don't think you will be able to hit from Postman (externally).
Even if you are able to hit it via SSO or what not, still try setting an User-Agent...