if i want to pass data from map function to the s...
# suitescript
s
if i want to pass data from map function to the summary was using this AND then in sumary function shouldnt key be the key i passed in ?
Copy code
context.write({
        key: salerodernumber,
        value: sku,
      }); function summarize(summary) {
    let amount = 0;
    let errors = "";
    summary.mapSummary.errors
      .iterator()
      .each(function (key, error, executionNo) {
        var errorObject = JSON.parse(error);
        log.error(`fulfilerrors ${key}`, errorObject);
b
the map summary errors iterator is for errors thrown during the map phase
s
correct i want the sales order id for the error thrown during the map section
b
Copy code
context.write({
        key: salerodernumber,
        value: sku,
      });
is not a thrown error
s
so i can make sure that when an error is throw in the map function the summary will have the sales order id
this is in side the map
Copy code
context.write({
        key: salerodernumber,
        value: sku,
      });
b
sales order id doesnt give me much to work with in this context
but your map errors will have the key of the map
your output will have the keys you wrote during the previous phase
s
I need to pass the internal id of the sales order that fails to save to the summary
b
share your code
s
Copy code
function map(context) {
    var data = JSON.parse(context.value);   let salerodernumber = data.id;    context.write({
        key: salerodernumber,
        value: sku,
      }); function summarize(summary) {
    let amount = 0;
    let errors = "";
    summary.mapSummary.errors
      .iterator()
      .each(function (key, error, executionNo) {
        var errorObject = JSON.parse(error);
        log.error(`fulfilerrors ${key}`, errorObject);
        let link =
          "<https://4994995.app.netsuite.com/app/accounting/transactions/salesord.nl?id=>" +
          key;
b
not enough code to reproduce
you get generic advice
throw your own error, or add your own properties to the error
s
Copy code
let salerodernumber = data.id
how can i have this aviibile in the summary of errors ?
b
catch the thrown error
throw your own with the salesordernumber in it
alternatively throw the same error but add a new property to it
s
i dont want to throw an error
i want it inside the error summary
b
you have no choice
the key in the map summary is the key of the map
s
it was working untill last week
b
if you really want it to work that way, then you need to change getInputData
s
meaning instead of array a search object ?
b
mapContext.key details how the key is chosen
you need to arrange it so that the ley is your order number
s
doesnt this do that
Copy code
context.write({
        key: salerodernumber,
        value: sku,
      })
b
thats choosing the key for the next stage
s
if i throw an error in the map section it wont be included inside the summary of errors ??
b
its probably easier to throw the error and observe what happens
s
that will not give me the option to send email of all the errors
b
why not?
s
if im throwing eror in the map stage then this code wont work
Copy code
function summarize(summary) {
    let amount = 0;
    let errors = "";
    summary.mapSummary.errors
      .iterator()
      .each(function (key, error, executionNo) {
        var errorObject = JSON.parse(error);
        log.error(`fulfilerrors ${key}`, errorObject);
        let link =
          "<https://4994995.app.netsuite.com/app/accounting/transactions/salesord.nl?id=>" +
          key;
        amount += 1;
        errors += `<tr><td>${amount}</td><td> <a href=${link}>${key}</a> </td > <td> ${errorObject.message || "No Meaningful message"
          } </td ><td>${executionNo}</td></tr>`;
        return true;
      });

    var date = new Date().toISOString().substring(0, 10);
    var time = summary.seconds;
    var minutes = Math.floor(time / 60);
    var subject = `>The  mass-fufil  ran for ${minutes} min with ${amount}errors `;
    //     summary.inputSummary.usage
    //   )} were created ${summary.usage}`;
    var body = `
        <style>
  table, th, td {
    border: 1px solid black;
  }
  </style>
        <table cellspacing="0" cellpadding="25" border="10" style="font-family: Arial, sans-serif; text-align: center;">
    <thead>
      <tr>
        <th style="border: 1px solid rgb(255, 0, 0);">count</th>
        <th>Salsess order id :</th>
        <th>Error Message Summary:</th>
        <th>Attempts</th>

      </tr>
    </thead>
    <tbody>
      ${errors}

    </tbody>
    </table>`;
b
experiment with the difference between summaryContext.output and mapSummary.errors
s
do you mean if i add this to the end of the map , then the only key value will be the ones thrown ?
Copy code
summary.output.iterator().each(function (key, value){
Copy code
} try {
       var id = fulfillmentRecord.save();
    } catch (e) {
     let salerodernumber = data.id;
    context.write({
      key: salerodernumber,
      value: e.message || JSON.stringify(e) || "No Meaningful message",
    });
    }
b
experiment with how the different summary objects work, you dont really want to duplicate or misuse them