Is it possible to use redirect.toRecordTransform a...
# suitescript
s
Is it possible to use redirect.toRecordTransform and transform with changes on line level information? Thinking quite broadly - maybe even trying to N/cache to then load the cache on UE executing on create? Any other ideas?
1
b
make your client script do stuff
think carefully about doing it beforeLoad, sourcing does not work well there
s
the current use case is the user wants to pick lines from a suitelet before transform, but they don't want to save the record immediately after the transform, which is why I'm trying to see if I can do redirect.toRecordTransform from the suitelet. in the case of a client script, i'll have to pass the information I want to change via the url right? actually maybe i can use the options.parameters in redirect.toRecordTransform and store whatever line level information I need to execute as a json... i'll try it out, thanks @battk
b
I belive you might be able to do arrays
for your url parameters
though there isnt really agreement on how that should be done
i find the qs npm module tends to work okay to smooth out the differences
your plan for json should be okay as long as you dont hit your browser's limits for query parameter length
keanu thanks 1
m
I've passed json objects as url parameter just base64 encoded and worked well
Copy code
function encodeBase64UrlSafe(object) {
  var stringified = JSON.stringify(object);

  var base64UrlSafeMap = {
    "+": "-",
    "/": "_",
    "=": "",
  };

  var encoded = nlapiEncrypt(stringified, "base64");

  Object.keys(base64UrlSafeMap).forEach(function (searchValue) {
    encoded = encoded.replace(searchValue, base64UrlSafeMap[searchValue]);
  });

  return encoded;
}
🙌 1
b
i would trust N/redirect's parameter escaping
🙌 1
m
The script on the sending end was SS1.0
This is what I used on receiving end which (SS2.0 Suitelet)
Copy code
/**
   * Helper function to decode the script parameters that are passed from the Supplier Invoice User Event Script
   * They are passed as stringified JavaScript objects that are Base64 (Url Safe) encoded
   *
   * @param context script context to read parameters from
   * @param {string} parameter name of the url parameter
   * @returns {any}
   */
  function getBase64EncodedJsonParameter(context, parameter) {
    const encoded = context.request.parameters[parameter];

    if (!encoded) {
      throw error.create({
        name: "CARS_REQUIRED_PARAM",
        message: `Missing required parameter "${parameter}"`,
      });
    }

    let decoded;

    try {
      decoded = encode.convert({
        inputEncoding: encode.Encoding.BASE_64_URL_SAFE,
        outputEncoding: encode.Encoding.UTF_8,
        string: encoded,
      });
    } catch {
      throw error.create({
        name: "CARS_INVALID_PARAM",
        message: `Invalid value for "${parameter}" parameter. Unable to decode from Base64UrlSafe`,
      });
    }

    try {
      return JSON.parse(decoded);
    } catch {
      throw error.create({
        name: "CARS_INVALID_PARAM",
        message: `Invalid value for "${parameter}" parameter. Unable to parse as JSON`,
      });
    }
  }
🙌 2
s
I thought all modern browsers support huge querystrings... I seem to recall there being an exception to that but maybe it was IIS or something (the receiving web server at the time)
m
Find this via quick googling: https://stackoverflow.com/a/812962
s
I would be careful when using cache. If there is any server restart occurs in between, content in the cache will be lost. It is recommended to use it for data that can be queried easily.
👍 2
m
Cache is intended for improving performance, not passing data