Kris Wood
06/04/2024, 3:11 PM{
"type": "error.SuiteScriptError",
"name": "UNEXPECTED_ERROR",
"message": null,
"id": "bef8e13d-64da-4053-b060-9012550c1575-2d323032342e30362e3034",
"stack": [
"each(N/searchObject)",
"getInputData(/SuiteScripts/exportMessagesMR.js:42)"
],
"cause": {
"type": "internal error",
"code": "UNEXPECTED_ERROR",
"details": null,
"userEvent": null,
"stackTrace": [
"each(N/searchObject)",
"getInputData(/SuiteScripts/exportMessagesMR.js:42)"
],
"notifyOff": false
},
"notifyOff": false,
"userFacing": false
}
Anthony OConnor
06/04/2024, 3:13 PMKris Wood
06/04/2024, 3:13 PMlog.debug({ title: 'Deployment Search', details: deploymentSearch });
deploymentSearch.run().each(function (result) {
log.debug({ title: 'Deployment Id: ', details: result.id });
Anthony OConnor
06/04/2024, 3:13 PMKris Wood
06/04/2024, 3:13 PMKris Wood
06/04/2024, 3:14 PMfunction getInputData() {
try {
// Get the last run time from the script parameter
var lastRunTime = runtime.getCurrentScript().getParameter({ name: 'custscript_last_run_time' });
log.debug({ title: 'Last Run Time', details: lastRunTime });
// If last run time is null, set it to yesterday at midnight
if (!lastRunTime) {
lastRunTime = new Date();
lastRunTime.setHours(0, 0, 0, 0);
lastRunTime.setDate(lastRunTime.getDate() - 1);
}
// Load the deployment record
var scriptObj = runtime.getCurrentScript();
log.debug('Deployment Id: ' + scriptObj.deploymentId); // customdeploy_exportmessages_mr
// find the deployment record
var deploymentSearch = search.create({
type: "scriptdeployment",
filters:
[
["scriptid", "is", scriptObj.deploymentId],
"AND",
["script.scriptid", "anyof", scriptObj.id]
],
columns:
[
search.createColumn({ name: "script", label: "Script ID" })
]
});
log.debug({ title: 'Deployment Search', details: deploymentSearch });
deploymentSearch.run().each(function (result) {
log.debug({ title: 'Deployment Id: ', details: result.id });
// load the deployment record
var deploymentRecord = record.load({
type: 'scriptdeployment',
id: result.id
});
log.debug({ title: 'Testing after load', details: deploymentRecord.id });
// set the last run time to now
deploymentRecord.setValue({
fieldId: 'custscript_last_run_time',
value: new Date()
});
// save the deployment record
deploymentRecord.save();
return false;
});
// Search messages created after the last run time, the only column we need is internalid
var messageSearch = search.create({
type: 'message',
filters: [
['created', 'after', lastRunTime]
],
columns: ['internalid']
});
return messageSearch;
} catch (e) {
log.error({
title: 'Error in getInputData',
details: e.toString()
});
}
}
Kris Wood
06/04/2024, 3:14 PMKris Wood
06/04/2024, 3:16 PMdeploymentSearch.run().each(function (result) {
Kris Wood
06/04/2024, 3:16 PMAnthony OConnor
06/04/2024, 3:19 PMAnthony OConnor
06/04/2024, 3:21 PMAnthony OConnor
06/04/2024, 3:21 PMKris Wood
06/04/2024, 3:21 PMAnthony OConnor
06/04/2024, 3:21 PMKris Wood
06/04/2024, 3:21 PMAnthony OConnor
06/04/2024, 3:21 PMKris Wood
06/04/2024, 3:22 PMAnthony OConnor
06/04/2024, 3:22 PMKris Wood
06/04/2024, 3:22 PMAnthony OConnor
06/04/2024, 3:22 PMKris Wood
06/04/2024, 3:23 PMKris Wood
06/04/2024, 3:23 PMAnthony OConnor
06/04/2024, 3:23 PMKris Wood
06/04/2024, 3:23 PM#
VIEW
TYPE
TITLE
DATE
TIME
USER
DETAILS
REMOVE
1 View Audit Summary 6/4/2024 8:57 am -System- Usage units consumed: 10 Concurrency units consumed: 1 Number of yields: 0 Input Summary: {"type":"mapreduce.InputSummary","dateCreated":"2024-06-04T14:56:31.648Z","seconds":0,"usage":10} Map Summary: {"type":"mapreduce.MapSummary","dateCreated":"2024-06-04T14:56:44.331Z","seconds":0,"usage":0,"concurrency":1,"yields":0} Reduce Summary: {"type":"mapreduce.ReduceSummary","dateCreated":"1970-01-01T00:00:00.000Z","seconds":0,"usage":0,"concurrency":1,"yields":0} Remove
2 View Error Error in getInputData 6/4/2024 8:56 am -System- {"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"id":"bef8e13d-64da-4053-b060-9012550c1575-2d323032342e30362e3034","stack":["each(N/searchObject)","getInputData(/SuiteScripts/exportMessagesMR.js:42)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace":["each(N/searchObject)","getInputData(/SuiteScripts/exportMessagesMR.js:42)"],"notifyOff":false},"notifyOff":false,"userFacing":false} Remove
3 View Debug Deployment Search 6/4/2024 8:56 am -System- {"type":"scriptdeployment","id":-1,"filters":[{"name":"scriptid","operator":"is","values":["customdeploy2"],"isor":false,"isnot":false,"leftparens":0,"rightparens":0},{"name":"scriptid","join":"script","operator":"anyof","values":["customscript_exportmessages_mr"],"isor":false,"isnot":false,"leftparens":0,"rightparens":0}],"columns":[{"name":"script","join":null,"summary":null,"label":"Script ID","type":null,"function":null,"formula":null,"sortdir":"NONE","whenorderedby":null,"whenorderedbyjoin":null,"whenorderedbyalias":null}],"settings":null,"title":null,"scriptId":null,"isPublic":false,"packageId":null} Remove
4 View Debug Deployment Id: customdeploy2 6/4/2024 8:56 am -System- Remove
5 View Debug Last Run Time 6/4/2024 8:56 am -System-
Anthony OConnor
06/04/2024, 3:24 PMKris Wood
06/04/2024, 3:24 PMKris Wood
06/04/2024, 3:24 PMKris Wood
06/04/2024, 3:24 PMKris Wood
06/04/2024, 3:24 PMKris Wood
06/04/2024, 3:25 PMKris Wood
06/04/2024, 3:25 PMKris Wood
06/04/2024, 3:25 PMClay Roper
06/04/2024, 3:26 PMKris Wood
06/04/2024, 3:27 PMKris Wood
06/04/2024, 3:27 PMKris Wood
06/04/2024, 3:28 PMbattk
06/04/2024, 3:39 PMbattk
06/04/2024, 3:39 PMscriptObj.id
Anthony OConnor
06/04/2024, 3:44 PMAnthony OConnor
06/04/2024, 3:45 PMAnthony OConnor
06/04/2024, 3:46 PMvar result = deploymentSearch.run().getRange(0,1);
but it doesn't really matter i supposeKris Wood
06/04/2024, 3:49 PMKris Wood
06/04/2024, 3:49 PMKris Wood
06/04/2024, 3:50 PMScript Id: customscript_exportmessages_mr
Kris Wood
06/04/2024, 3:50 PMAnthony OConnor
06/04/2024, 3:50 PMKris Wood
06/04/2024, 3:50 PMKris Wood
06/04/2024, 3:50 PMKris Wood
06/04/2024, 3:51 PMKris Wood
06/04/2024, 3:51 PMAnthony OConnor
06/04/2024, 3:51 PMKris Wood
06/04/2024, 3:52 PMKris Wood
06/04/2024, 3:55 PMKris Wood
06/04/2024, 3:55 PMAnthony OConnor
06/04/2024, 3:58 PMAnthony OConnor
06/04/2024, 3:58 PMKris Wood
06/04/2024, 3:59 PMAnthony OConnor
06/04/2024, 3:59 PMKris Wood
06/04/2024, 3:59 PMbattk
06/04/2024, 4:00 PMdeploymentRecord.setValue({
fieldId: 'custscript_last_run_time',
value: new Date()
});
is not good enoughbattk
06/04/2024, 4:00 PMbattk
06/04/2024, 4:00 PMbattk
06/04/2024, 4:02 PMbattk
06/04/2024, 4:02 PMClay Roper
06/04/2024, 4:02 PMKris Wood
06/04/2024, 4:20 PMKris Wood
06/04/2024, 4:23 PMbattk
06/04/2024, 4:27 PMbattk
06/04/2024, 4:27 PMbattk
06/04/2024, 4:27 PMKris Wood
06/04/2024, 4:30 PMKris Wood
06/04/2024, 4:30 PMKris Wood
06/04/2024, 4:31 PMbattk
06/04/2024, 4:34 PMKris Wood
06/04/2024, 4:35 PMKris Wood
06/04/2024, 4:36 PMbattk
06/04/2024, 4:37 PMbattk
06/04/2024, 4:38 PMKris Wood
06/04/2024, 4:42 PMLast Run Time: 2024-06-04T16:39:14.000Z
Kris Wood
06/04/2024, 4:43 PMbattk
06/04/2024, 4:43 PMKris Wood
06/04/2024, 4:44 PMfunction getInputData() {
try {
// Get the last run time from the script parameter
var lastRunTime = runtime.getCurrentScript().getParameter({ name: 'custscript_last_run_time' });
log.debug({ title: 'Last Run Time', details: lastRunTime });
// If last run time is null, set it to yesterday at midnight
if (!lastRunTime) {
lastRunTime = new Date();
lastRunTime.setHours(0, 0, 0, 0);
lastRunTime.setDate(lastRunTime.getDate() - 1);
}
// Load the deployment record
var scriptObj = runtime.getCurrentScript();
log.debug('Deployment Id: ' + scriptObj.deploymentId); // customdeploy_exportmessages_mr
log.debug('Script Id: ' + scriptObj.id); // customscript_exportmessages_mr
// find the deployment record
var deploymentSearch = search.create({
type: "scriptdeployment",
filters:
[
["scriptid", "is", scriptObj.deploymentId],
"AND",
["script.scriptid", "is", scriptObj.id]
],
columns:
[
search.createColumn({ name: "script", label: "Script ID" })
]
});
log.debug({ title: 'Deployment Search', details: deploymentSearch });
deploymentSearch.run().each(function (result) {
log.debug({ title: 'Deployment Id: ', details: result.id });
// load the deployment record
var deploymentRecord = record.load({
type: 'scriptdeployment',
id: result.id
});
log.debug({ title: 'Testing after load', details: deploymentRecord.id });
// set the last run time to now
deploymentRecord.setValue({
fieldId: 'custscript_last_run_time',
value: new Date()
});
// save the deployment record
deploymentRecord.save();
return false;
});
// make sure lastRunTime is in NetSuite date format
// lastRunTime should be a Date object initially convert it to string
runTimeString = lastRunTime.toISOString();
// use N/format to parse the string to a NetSuite date format
lastRunTime = format.parse({ value: runTimeString, type: format.Type.DATETIME });
log.debug({ title: 'Last Run Time', details: lastRunTime });
} catch (e) {
log.error({
title: 'Error in getInputData',
details: e.toString()
});
}
// Search messages created after the last run time, the only column we need is internalid
return search.create({
type: 'message',
filters: [
['created', 'onorafter', lastRunTime]
],
columns: ['internalid']
});
}
Kris Wood
06/04/2024, 4:44 PMbattk
06/04/2024, 4:45 PMbattk
06/04/2024, 4:45 PMbattk
06/04/2024, 4:45 PMKris Wood
06/04/2024, 4:46 PMvar messageSearchObj = search.create({
type: "message",
filters:
[
["messagedate","onorafter","6/3/2024 12:00 am","6/3/2024 12:00 am"]
],
columns:
[
search.createColumn({name: "internalid", label: "Internal ID"})
]
});
var searchResultCount = messageSearchObj.runPaged().count;
log.debug("messageSearchObj result count",searchResultCount);
messageSearchObj.run().each(function(result){
// .run().each has a limit of 4,000 results
return true;
});
/*
messageSearchObj.id="customsearch1717519555717";
messageSearchObj.title="Message Integration Search (copy)";
var newSearchId = messageSearchObj.save();
*/
battk
06/04/2024, 4:46 PMbattk
06/04/2024, 4:46 PMbattk
06/04/2024, 4:47 PMKris Wood
06/04/2024, 4:47 PMKris Wood
06/04/2024, 11:47 PMKris Wood
06/04/2024, 11:49 PM// Search for the deployment record using the internal ID of the script
var deploymentSearch = search.create({
type: 'scriptdeployment',
filters: [
['script', 'anyof', scriptInternalId]
],
columns: [
search.createColumn({ name: 'internalid', label: 'Internal ID' })
]
});
deploymentSearch.run().each(function (result) {
var deploymentId = result.id;
// Load the deployment record
var deploymentRecord = record.load({
type: 'scriptdeployment',
id: deploymentId
});
var newDate = new Date();
// Set the last run time to now
deploymentRecord.setValue({
fieldId: 'custscript_last_run_time',
value: newDate
});
log.debug({ title: 'checking if value was set', details: deploymentRecord.getValue({ fieldId: 'custscript_last_run_time' }) });
// Save the deployment record
var deploymentStatus = deploymentRecord.save();
log.debug({ title: 'Deployment Record Saved', details: "Deployment ID: " + deploymentStatus + ", New Last Run Time: " + newDate });
return false; // Break after the first deployment result
});
Kris Wood
06/04/2024, 11:51 PMKris Wood
06/04/2024, 11:51 PMKris Wood
06/04/2024, 11:53 PMbattk
06/04/2024, 11:56 PMKris Wood
06/04/2024, 11:57 PM- ['script', 'anyof', scriptInternalId]
+ ['script', 'anyof', scriptInternalId], "AND",
+ ['scriptid', 'is', scriptObj.deploymentId]