Any idea anyone if is possible to read/know the ta...
# suitescript
a
Any idea anyone if is possible to read/know the taskId of the Map Reduce within the same Map Reduce?
c
Like the script ID? You can get any info like that w/ the N/runtime module
a
The Script was launch with task, I need the taskID if possible...
c
the map reduce script wouldn't know that
you can create the task, then set the a custom param on the map/reduce deployment before you submit the task possibly so the map/reduce can read that and know it was from a certain task
not sure the use case for why you'd need this though
f
So you started a task and you want the last taskId? I have a snippet that uses the search API for that
Not sure if thats what you where asking for and not sure if its really that elegant but:
Copy code
function getStatus(scriptId) {
            const taskSearch = search.create({
                type: search.Type.SCHEDULED_SCRIPT_INSTANCE,
                filters: [
                    {
                        join: "script",
                        name: "scriptid",
                        operator: <http://search.Operator.IS|search.Operator.IS>,
                        values: [scriptId]
                    },
                ],
                columns: [
                    "taskid",
                    {
                        name: "datecreated",
                        sort: search.Sort.DESC
                    }
                ],
            });

            const taskRecord = taskSearch.run().getRange({start: 0, end: 1});
            if (taskRecord.length === 0) {
                return null;
            }

            return task.checkStatus({taskId: taskRecord[0].getValue({name: "taskid"})});
        }
a
You only get the taskId after you submit @creece
m
@alien4u can you tell me your use case why you need the taskID inside of map reduce
a
The use case is: - Have a Suitelet which generato POs through a MR launched with task - The Map Reduce taskId is passed to another Suitelet which monitor that taskId for completion and then show results. - Here is the problem, which results? These 10 Purchase Orders I just create or the 20 from the last week where the created from is the same than this? Having the taskId would allow me to use a portion as a batch id to write it to the created POs and then.show result filtering on that.
@Michelle Xue This is now solve because I use the tranid + random alphanumeric characters to create a batch ID which also lead me to another problem, after string concatenation even if typeof validate the variable as string you can't pass that string as parameter to the Map Reduce... you need to convert the String to String(funny enough)...