Hi everyone, can i use SS 2.0 sessions module to s...
# suitescript
r
Hi everyone, can i use SS 2.0 sessions module to store global rules for all other scripts to retrieve as key-value pairs at any time?? Such is used for storing business rules or content which will be used anytime scripts run.
b
Ive never really seen a use for the runtime session
Not sure how you would place rules in a session
I personally say use a custom module
💯 1
r
@battk Any examples i can look at for custom module? This storage has to persist key-value pair objects for use in every other script that is being run
b
are they the same values
r
it will be read from a set of static files
b
whats an example
r
like a blog or article or github.
b
what an example key
what an example value
r
Copy code
conditions: {
    any: [{
      all: [{
        fact: 'gameDuration',
        operator: 'equal',
        value: 40
      }, {
        fact: 'personalFoulCount',
        operator: 'greaterThanInclusive',
        value: 5
      }]
    }
something like this
b
i have no idea how that related to a blog or github
but you can make a module return that object
r
oh okay global objects could make sense
b
an example custom module could look like:
Copy code
define([], function() {
  return {
    conditions: {
      any: [
        {
          all: [
            {
              fact: "gameDuration",
              operator: "equal",
              value: 40
            },
            {
              fact: "personalFoulCount",
              operator: "greaterThanInclusive",
              value: 5
            }
          ]
        }
      ]
    }
  };
});
r
i want them to be read from a file thou as this bunch of files will be used outisde of netsuite. Also i dont want suitescript to constantly read/write the files
b
put it in a file and add the file's path to your scripts dependencies
r
how about global objects?
cause reading from a file constantly could introduce latency
b
no such thing
scripts don't share the same context
if you want objects, you should probably be using N/cache instead
i personally suspect that all attempts to place large amounts of data in a session or the cache will fail
r
why so?
maybe 5mb worth?
b
that is not a large amount of data
r
yep, not much
b
ill simply say that the custom module will get you what you want
dont know about session
cache may require you to split up keys and values so that the values are less than 500kb
r
Thanks