You probably want `findTime1().values` and `findTr...
# suitescript
e
You probably want
findTime1().values
and
findTransaction().values
instead, or have those functions return the
values
directly instead.
👍 1
n
I'm getting a null result from function findTime().values In the function search
Copy code
function findTime1() {
    log.audit({
      title: "Finding Time1...",
      details: "Executed",
    });
    return search.create({
      type: "timebill",
      filters:
      [
        ["item.account","anyof","183"],
        "AND",
        ["job.internalidnumber","equalto","114890"]
      ],
      columns:
      [
        search.createColumn({
          name: "entitynumber",
          join: "job",
          summary: "GROUP",
          label: "Number"
        }),
        search.createColumn({
          name: "formulanumeric5",
          summary: "SUM",
          formula: "CASE WHEN {durationdecimal} IS NULL THEN 0 ELSE {durationdecimal} END",
          label: "Custentity21"
        })
      ]
    }).run().getRange(0, 10);
  };
Should i instead do:
Copy code
var findTime = findTime1().run().getRange(0, 10);

    for (var i = 0; i < findTime.length; i++)  {
      var prjId = findTime [i].getValue({
        name: 'entityid'
      });
array += prjId
Or am I over complicating it? I'm missing something.
b
umm
you are doing some weird things
the first argument to groupBy is supposed to be your array
im guessing findTime1 and findTransaction return an array of search results
so you have an array, whose elements are arrays of search results
If you wanted to merge your arrays, you need to flatten it to an array of search results, (possibly by simply concating the two arrays)
secondly your grouping function is [iteratee=_.identity("GROUP(job.entitynumber)")]
im honestly not sure that that does in the context of _.groupBy
but its supposed to be a function that returns the values that you want to group by
n
haha I am. I want to do it better 🙂
yes findTime1 and findTransacion are function searches, the 2 arrays.
I was trying to concat the two, then stopped as I was going with the groupBy but im obviously misunderstanding how to use it.
b
unless your two search results share the same columns, i wouldn't group them
n
That the tricky part. They dont, only the job.entity to link the two, and add the extra hours column, that iIcant pull into a transaction search. The common key would be the job.entityId, and I simply just want to add another column to the result and group by. As the join between entity and transaction records are missing. Unless there's a better way to join record data?
Maybe im going about this all wrong
b
when you groupBy your search results, you will get something that looks like
{"9712": [TimeResult1, TimeResult2,TransactionResult1,TransactionResult2]}
at some point you will have to get values from the columns
im assuming you dont want to guess which search result columns to use
n
I was noticing that, which then got me thinking.
Copy code
context.response.writePage({
      pageObject: renderList(mergedArray)
    });
wouldn't do anything with it
as the structure of the object is not what NS understands
of course, I want to build some math between the linked array values too
b
meh
dunno what you are trying to do
ill answer your original question
Copy code
_.groupBy(findTime1().concat(findTransaction()), function(searchResult) {
  return searchResult.getValue({
    name: "entitynumber",
    join: "job",
    summary: "GROUP"
  });
});
👍 1
will output an object where the keys are entitynumbers and the values are arrays of search results with that entity number
n
its tricky, I'm collecting values from transactions, and time entries that contain hours. Once i have that I then need to calculate values from the results.
Thanks battk, much appreciated! I'll give this a try.
Why would my function findTime().values not work? I still have a lot to learn.
b
without seeing your code, my guess is that findTime().values is undefined (or if running on 2.1 a function)
n
suitelet
I have a bunch of junk in there as I was trying to figure out how the lodash functions worked
b
still dont know where your findTime function is
n
My apologies findTime1()
very bottom
b
findTime1() returns an array. [].values is undefined
n
as values are not declared, ok
Thank you very much battk 🙂 !
b
you should be ashamed of your ugly formulas
🙄 1
n
hahaha, I am 😀