Hi everyone, I am trying to create a RESTlet that ...
# suitescript
a
Hi everyone, I am trying to create a RESTlet that brings me all saved searches that start with a specific word, but it is throwing several errors. When I put the title in the filter, do you know why this might be happening? the error is: Cannot find function startwith in object Payment File Template Requests. the code is this:
var mySearch = search.create({
type: search.Type.SAVED_SEARCH,
columns: [
'internalid',
'title',
'owner',
'recordtype'
]
});
var searchResult = mySearch.run().getRange({
start: 0,
end: 1000
});
var results = [];
searchResult.forEach(function(result) {
var titlev = result.getValue({ name: 'title' });
titlev = titlev ? String(titlev) : '';
titlev = 	titlev.toString();
if(titlev.startwith("SD")){
log.audit({
title: 'Search Result',
details: 'ID: ' + result.getValue({ name: 'internalid' }) +
', Title: ' + titlev +
', Owner: ' + result.getText({ name: 'owner' }) +
', Record Type: ' + result.getValue({ name: 'recordtype' })
});
results.push({
id: result.getValue({ name: 'internalid' }),
title: titlev,  // Usar titlev aquí también
owner: result.getText({ name: 'owner' })
});
}
});
a
so you get an error with a filter, and then share the code that doesn't have the filter? guessing the issue based on the error is that search.Operator.STARTWITH isn't an operator, its misssing an S search.Operator.STARTSWITH or i guess
startswith
vs.
startwith
if you're not using he enum
🙌 1
b
You are probably running this code in SS2.0 which doesn't have startsWith which is an ES6 function, try it in 2.1, also the function name is "startsWith" not "startWith". Alternatively you can use indexOf instead in SS2.0.