I am trying to retrieve a specific system note below:
var noteSearch = search.create({
type: record.Type.NOTE,
columns: ['id', 'title', 'notetype', 'notedate', 'note'],
filters: [
search.createFilter({
name: 'id',
operator: search.Operator.EQUALTO,
values: 33
})
]
});
var noteSearchResultSet = noteSearch.run();
The error I'm getting:
{"type":"error.SuiteScriptError","name":"SSS_INVALID_SRCH_COL","message":"An nlobjSearchColumn contains an invalid column, or is not in proper syntax: id.","stack":["Error\n at Object.onRequest (...)"],"cause":{"type":"internal error","code":"SSS_INVALID_SRCH_COL","details":"An nlobjSearchColumn contains an invalid column, or is not in proper syntax: id.","userEvent":null,"stackTrace"
EDIT:
internalid has same error:
var noteSearch = search.create({
type: record.Type.NOTE,
columns: ['internalid', 'title', 'notetype', 'notedate', 'note'],
filters: [
search.createFilter({
name: 'internalid',
operator: search.Operator.EQUALTO,
values: 33
})
]
});
The note in question:
Try using another filter type: 'is' maybe. I guess the code below could work using either 'id' or 'internalid'.
var noteSearch = search.create({
type: record.Type.NOTE,
columns: ['internalid', 'title', 'notetype', 'notedate', 'note'],
filters: [
['internalid', 'is', 33]
]
});
Related
I need to make conditions on my filters in my search. I have browsed through a lot of forums without finding functional solutions. After many inconclusive tests, I come to you for help.
My code :
function retrieveVendor(vendorValues){
var subsidiaryIdFilter = SEARCHMODULE.createFilter({
name: 'internalid',
join: 'subsidiary',
operator: SEARCHMODULE.Operator.ANYOF,
values: vendorValues.companyCode
});
var addressFilter = SEARCHMODULE.createFilter({
name: 'address',
join: 'vendor',
operator: SEARCHMODULE.Operator.CONTAINS,
values: vendorValues.street
});
var cityFilter = SEARCHMODULE.createFilter({
name: 'city',
join: 'vendor',
operator: SEARCHMODULE.Operator.CONTAINS,
values: vendorValues.city
});
var zipFilter = SEARCHMODULE.createFilter({
name: 'zipcode',
join: 'vendor',
operator: SEARCHMODULE.Operator.CONTAINS,
values: vendorValues.postalCode
});
var vendorIdTest = SEARCHMODULE.create({
type: SEARCHMODULE.Type.VENDOR_SUBSIDIARY_RELATIONSHIP,
columns: [
SEARCHMODULE.createColumn({name:'entityid', join: 'vendor'}),
SEARCHMODULE.createColumn({name:'internalid', join: 'subsidiary'}),
SEARCHMODULE.createColumn({name:'address', join: 'vendor'})
],
filters: [
subsidiaryIdFilter, 'and', [addressFilter, 'or', zipFilter]
]
});
var nbOfResults = vendorIdTest.runPaged().count;
var resultArray = [];
var aa = vendorIdTest.run().each(function(result){
var obj ={};
obj['vendorName'] = result.getValue({
name: 'entityid',
join: 'vendor'
});
obj['idOfSubsidiary'] = result.getValue({
name: 'internalid',
join: 'subsidiary'
});
obj['vendorAddress'] = result.getValue({
name: 'address',
join: 'vendor'
});
resultArray.push(obj);
return true;
});
var result = nbOfResults + ' : ' + JSON.stringify(resultArray);
return result;
}
And here are all the syntaxes tried on the 'filters' parameter of my search :
subsidiaryIdFilter, 'and', [addressFilter, 'or', zipFilter]
[subsidiaryIdFilter, 'and', [addressFilter, 'or', zipFilter]]
subsidiaryIdFilter, 'and', (addressFilter, 'or', zipFilter)
subsidiaryIdFilter && (addressFilter, 'or', zipFilter)
subsidiaryIdFilter && (addressFilter || zipFilter)
I have of course searched in the SuiteScript documentation but nothing is mentioned on this subject. Thank you for your help.
It doesn't really work that way. Filters created with search.createFilter are all implicitly ANDed together.
What you need is filter expressions which have a different syntax. You cannot mix filters and filter expressions so:
var vendorIdTest = SEARCHMODULE.create({
type: SEARCHMODULE.Type.VENDOR_SUBSIDIARY_RELATIONSHIP,
columns: [
SEARCHMODULE.createColumn({name:'entityid', join: 'vendor'}),
SEARCHMODULE.createColumn({name:'internalid', join: 'subsidiary'}),
SEARCHMODULE.createColumn({name:'address', join: 'vendor'})
],
filters: [
['subsidiary', 'anyof', vendorValues.companyCode], 'AND',
[
[
['vendor.address', 'contains', vendorValues.street ], 'AND',
['vendor.city', 'is', vendorValues.city] // i'm guessing you meant to include this
], 'OR',
['vendor.zipcode', 'contains', vendorValues.postalCode]
]
]
});
Thanks to the Plugin (https://chrome.google.com/webstore/detail/netsuite-search-export/gglbgdfbkaelbjpjkiepdmfaihdokglp), I found the syntax to put AND and OR between my filters with joins:
var subsidiaryIdFilter = ["subsidiary.internalid", "anyof", vendorValues.companyCode];
var addressFilter = ["vendor.addresslabel", "contains", vendorValues.street];
var cityFilter = ["vendor.city", "contains", vendorValues.city];
var vendorNameFilter = ["vendor.entityid", "contains", vendorValues.name];
var zipFilter = ["vendor.zipcode", "contains", vendorValues.postalCode];
var addressSearch = SEARCHMODULE.create({
type: SEARCHMODULE.Type.VENDOR_SUBSIDIARY_RELATIONSHIP,
columns: [
SEARCHMODULE.createColumn({name:'entityid', join: 'vendor', sort : SEARCHMODULE.Sort.ASC})
],
filters: [
subsidiaryIdFilter, "AND", [zipFilter, "OR", cityFilter, "OR", addressFilter]
]
});
SuiteScript 2 Suitelet.
In the following code, why would count be zero for an itemInternalId that has prices in the UI?
var searchObj = search.create({
type: 'item',
filters: [
search.createFilter({
name: 'internalid',
operator: search.Operator.IS,
values: [itemInternalId]
})
],
columns: [
search.createColumn({
name: 'unitprice',
join: 'pricing',
}),
search.createColumn({
name: 'quantityrange',
join: 'pricing',
}),
search.createColumn({
name: 'maximumquantity',
join: 'pricing',
}),
search.createColumn({
name: 'minimumquantity',
join: 'pricing',
})
]
});
var count = searchObj.runPaged().count;
itemInternalId is of a matrix child item and count is zero.
If I set itemInternalId to its sibling matrix child item then count is greater than zero.
Both items appear to have identical pricing configured in the UI.
You'll need to use search.Operator.ANYOF in your search filters.
I have a crazy array look like this:
const data = [
[{ Name: 'Name 1', Block: [{Id: "1"}, {Id: "2"}] }],
[{ Name: 'Name 2', Block: [{Id: "3"}, {Id: "4"}] }],
]
I want to map Block to a single array to look like this:
[ { Id: '1' },
{ Id: '2' },
{ Id: '3' },
{ Id: '4' }
]
I have tried doing like this:
const data = [
[{ Name: 'Name 1', Block: [{Id: "1"}, {Id: "2"}] }],
[{ Name: 'Name 2', Block: [{Id: "3"}, {Id: "4"}] }],
]
const idList = data.map(blockData => {
return blockData[0].Block;
});
console.log(idList)
What did I do wrong?
.map will create a new item for every index of the old array. If your input array has 2 items, the output array will also only have 2 items - but you want 4 items, so .map won't work. Use flatMap instead, to flatten:
const data = [
[{ Name: 'Name 1', Block: [{Id: "1"}, {Id: "2"}] }],
[{ Name: 'Name 2', Block: [{Id: "3"}, {Id: "4"}] }],
];
const idList = data.flatMap(([{ Block }]) => Block);
console.log(idList)
flatMap is only implemented on newer implementations, though - otherwise, use a polyfill or a different method, like reduceing into an array:
const data = [
[{ Name: 'Name 1', Block: [{Id: "1"}, {Id: "2"}] }],
[{ Name: 'Name 2', Block: [{Id: "3"}, {Id: "4"}] }],
];
const idList = data.reduce((a, [{ Block }]) => a.concat(Block), []);
console.log(idList)
your data is an array inside array so you should use map twice, Buth that will give you an array with 2 elements now you need to reduce or flatten the resulting array to get the desired output.
data.map(a=>{return a[0].Block.map(b=>{ return b})}).reduce((o, m) => [...m, ...o], [])
The most succinct way to do it would be with a reduce statement:
const reducer = (a, b) => a.concat(b[0].Block);
const idList = data.reduce(reducer, []);
This way it will be much clearer what you are trying to do.
I'm trying to load up all of the emails that have been sent from a transaction via SuiteScript 2.0.
When I run
record.getSublists()
it returns the following:
["item","activeworkflows","workflowhistory","custom8","messages","contacts","activities","usernotes","systemnotes","mediaitem","links","cases","partners","events","calls","tasks"]
However, when I then try to run the following:
record.getSublist('messages');
I receive an error.
I need to be able to check the date of the last email sent so I can determine whether or not to send a follow-up email.
The approach I typically take is to use the Search API to get this type of information:
require(['N/search'], function(search) {
var result = search.create({
type: 'transaction',
filters: [
['internalid', search.Operator.ANYOF, id], 'AND',
['mainline', search.Operator.IS, 'T'], 'AND',
['messages.messagetype', search.Operator.ANYOF, 'EMAIL'], 'AND',
['messages.isincoming', search.Operator.IS, 'F']
],
columns: [
search.createColumn({name: 'internalid', summary: search.Summary.GROUP}),
search.createColumn({name: 'messagedate', join: 'messages', summary: search.Summary.MAX}),
],
}).run().getRange({ start: 0, end: 1 });
var dateOfLastEmail = result[0].getValue({ name: 'messagedate', join: 'messages', summary: search.Summary.MAX });
});
How can I make case insensitive string filter in extjs. Following is the corresponding grid column.
var columns = [{
dataIndex: 'name',
header: 'NAME',
style: 'border: none;',
id: 'name',
sortable : true,
width: 141,
filter: {
type: 'string'
}
}
You need to specify the sortType on the field in the model: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.SortTypes-method-asUCString
Ext.define('MyModel', {
fields: [{
name: 'name',
sortType: 'asUCString'
}]
});