This topic contains 6 replies, has 0 voices, and was last updated by karenn 8 years, 2 months ago.
-
AuthorPosts
-
September 20, 2016 at 12:55 pm #1780
karennI am trying to write a scheduled script to traverse each of the results from a saved search. If I just use search.load and run it works fine. But when I try to use promise I get an error right away and I am not sure why. The error that is logged is
org.mozilla.javascript.EcmaError: TypeError: Cannot find function promise in object function loadSearch(options) {…}. (/SuiteScripts/PE Scripts 2.0/pe2_ss_costchanges.js#30)
Here is the script
/**
* @NApiVersion 2.0
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define([‘N/record’, ‘N/search’, ‘N/email’],
function(record, search, email) {
/**
* Definition of the Scheduled script trigger point.
*
* @param {Object} scriptContext
* @param {string} scriptContext.type – The context in which the script is executed. It is one of the values from the scriptContext.InvocationType enum.
* @Since 2015.2
*/
function execute(scriptContext)
{
//email.send({
// author : 6,
// recipients : 6,
// subject : ‘Cost Changes Start’,
// body : ‘Cost Changes updates started’
// });
search.load.promise({
type: search.Type.ITEM_RECEIPT,
id: ‘customsearch_pe_porecptcostchgs’
}).then(function (searchObj) {
return searchObj.run().each.promise(
function (result, index) {
var itemId = result.getValue({name: ‘internalid’, join: ‘item’});
log.debug(‘itemId: ‘ + itemId );
var itemRec = loadItemRec(itemId);
var abcCode = result.getValue({name: ‘custitem_abc_code’, join: ‘item’});
log.debug(‘abccode: ‘ + abcCode );
return true;
})
})
//this works!!
//var mySearch = search.load({id: ‘customsearch_pe_porecptcostchgs’});
//mySearch.run().each(function(result) {
// var itemId = result.getValue({name: ‘internalid’, join: ‘item’});
// log.debug(‘itemId: ‘ + itemId );
// var itemRec = loadItemRec(itemId);
// var abcCode = result.getValue({name: ‘custitem_abc_code’, join: ‘item’});
// log.debug(‘abccode: ‘ + abcCode );
// return true;
//});
}
function loadItemRec(itemid) {
var item = null;
itemok = false;
try
{
item = record.load({
type : record.Type.INVENTORY_ITEM,
id : itemid,
isDynamic : false
})
itemok = true;
}
catch(e)
{
try
{
item = record.load({
type : record.Type.ASSEMBLY_ITEM,
id : itemid,
isDynamic : false
})
itemok = true;
}
catch(e)
{
try
{
item = record.load({
type : record.Type.KIT_ITEM,
id : itemid,
isDynamic : false
})
itemok = true;
}
catch(e)
{
itemok = false;
//alert(“Unable to find item to determine type”);
}
}
}
if (itemok)
{
return item;
}
else
{
return null;
}
}
return {
execute: execute
};
});
I have found very few examples of scripts using promise so I am kind of flying blind here. Any help would be appreciated. Probably something stupid I am just not seeing.
Thanks!
Karen
This is a cached copy. Click here to see the original post. -
September 20, 2016 at 12:59 pm #1781
JCiroccoSimilar post from yesterday may help:
https://usergroup.netsuite.com/users…-https-promise
-
September 20, 2016 at 1:16 pm #1782
karennThanks John! Mine is strictly a Scheduled SuiteScript so I don;t think so but who knows. I am definitely missing something using promise
-
September 20, 2016 at 1:41 pm #1783
david.smithI don’t think you can use promise with a scheduled script. I could be wrong though.
-
September 20, 2016 at 1:45 pm #1784
chanarbonHi @karenn,
Please note that Promise API and Promise object is currently limited to client side. As of the moment, server side scripts are limited to the synchronous processes unlike client script which is user facing. Please check out SuiteAnswers ID 43804 (https://netsuite.custhelp.com/app/an…il/a_id/43804/) for more information.
-
September 20, 2016 at 1:48 pm #1785
david.smithkarenn You might want to consider using a map/reduce script. Much more efficient at traversing search results and doing something with them.
-
September 20, 2016 at 1:56 pm #1786
karennClient side…aha!! Missed that little tidbit. Thanks.
Map/Reduce I guess is my next try to figure out how to use that.
Thanks all!!
-
AuthorPosts
You must be logged in to reply to this topic.