Kevin Baxter
08/30/2023, 4:31 PMfunction getInputData() {
try {
var script = runtime.getCurrentScript();
var schoolId = script.getParameter({name: 'custscript_school_id'})
var schoolName = script.getParameter({name: 'custscript_school_name_param'})
var uniqueID = Math.floor(Math.random() * (Math.random() * 20) + 100) + 5
var anotherValue = uniqueID + 44
var array1 = []
var array2 = []
var array3 = []
var customSearch = search.create({
type: search.Type.CUSTOMER,
title: 'custsearch_' + anotherValue,
id: 'customsearch_customer_' + uniqueID,
isPublic: true,
filters:
['custentity_lf_school_record', 'is', schoolId],
columns:
[
search.createColumn({
name: "entityid",
sort: search.Sort.ASC,
label: "Name"
})
]
});
var assemblyItemSearch = search.create({
type: search.Type.ASSEMBLY_ITEM,
title: 'custsearch_' + anotherValue,
id: 'customsearch_assembly_' + uniqueID,
isPublic: true,
filters: [
["type", "anyof", "Assembly"],
"AND",
["isinactive", "any", ""],
"AND",
['custitem_lf_school', 'is', schoolId],
"AND",
['custitem_lf_school_name', 'is', schoolName],
],
columns:
[
search.createColumn({
name: "itemid",
sort: search.Sort.ASC,
label: "Name"
})
]
})
var inventoryItemsSearch = search.create({
type: search.Type.INVENTORY_ITEM,
title: 'custsearch_' + anotherValue,
id: 'customsearch_inventoryItem_' + uniqueID,
isPublic: true,
filters: [
["type", "anyof", "InvtPart"],
"AND",
["isspecialorderitem", "any", ""],
"AND",
['custitem_lf_school', 'is', schoolId],
"AND",
['custitem_lf_school_name', 'is', schoolName],
],
columns:
[
search.createColumn({
name: "itemid",
sort: search.Sort.ASC,
label: "Name"
})
]
})
customSearch.run().each(function (result) {
// .run().each has a limit of 4,000 results
array1.push(result);
return true;
});
assemblyItemSearch.run().each(function (result) {
array2.push(result);
return true;
})
inventoryItemsSearch.run().each(function (result) {
array3.push(result);
return true;
})
return [...array1, ...array2, ...array3]
} catch (e) {
log.debug("Error", e)
}
}
/**
* Defines the function that is executed when the map entry point is triggered. This entry point is triggered automatically
* when the associated getInputData stage is complete. This function is applied to each key-value pair in the provided
* context.
* @param {Object} mapContext - Data collection containing the key-value pairs to process in the map stage. This parameter
* is provided automatically based on the results of the getInputData stage.
* @param {Iterator} mapContext.errors - Serialized errors that were thrown during previous attempts to execute the map
* function on the current key-value pair
* @param {number} mapContext.executionNo - Number of times the map function has been executed on the current key-value
* pair
* @param {boolean} mapContext.isRestarted - Indicates whether the current invocation of this function is the first
* invocation (if true, the current invocation is not the first invocation and this function has been restarted)
* @param {string} mapContext.key - Key to be processed during the map stage
* @param {string} mapContext.value - Value to be processed during the map stage
* @since 2015.2
*/
const map = (mapContext) => {
try {
// var script = runtime.getCurrentScript();
// var standardRoy = script.getParameter({name: 'custscript_school_std_roy_perc'})
// var headwearRoy = script.getParameter({name: 'custscript_lf_school_hdwr_roy_perc'})
// var specialRoy = script.getParameter({name: 'custscript_lf_school_spec_roy_perc'})
var listID = JSON.parse(mapContext.value)
return listID.id
} catch (e) {
log.debug("Error Message:", e)
}
}
Clay Roper
08/30/2023, 4:32 PMKevin Baxter
08/30/2023, 4:34 PMClay Roper
08/30/2023, 4:37 PMClay Roper
08/30/2023, 4:39 PMClay Roper
08/30/2023, 4:42 PMKevin Baxter
08/30/2023, 4:45 PMKevin Baxter
08/30/2023, 4:45 PMKevin Baxter
08/30/2023, 4:45 PMClay Roper
08/30/2023, 4:54 PMbeforeSubmitContext.newRecord
differ significantly between those two contexts, which might trip up field validation in beforeSubmit scripts. Just something to keep an eye on.
I assume you'd be updating your getIntputData script to feed the record types and internal IDs? Also, if you move forward with the approach of pushing results to the return value, you can push it all to a single array instead of three different ones that you spread into a return value.
You might consider doing something like the following in getInputData
resultArray.push({
id: searchResult.getValue({ "internalid" }),
type: record.Type.ASSEMBLY_ITEM or record.Type.INVENTORY_ITEM or record.Type.CUSTOMER
})
You won't be able to set fields that start with custitem
on a Customer record btwbattk
08/30/2023, 5:04 PMbattk
08/30/2023, 5:05 PMbattk
08/30/2023, 5:06 PMOR
in the filter expressionbattk
08/30/2023, 5:13 PMKevin Baxter
08/30/2023, 6:26 PM