I have a script that needs to update a record due to his country.
so I have to make a save search and add a country filter - the problem is that I have the country code or country name but not the country id - the save search need to have the country id
var search_htsCodes = search.create({
type: "customrecordau_test_codes",
filters: [
["custrecord_au_part_number.internalidnumber", "equalto", item],
"AND",
["custrecord_au_country", "anyof", country] // HERE IS THE PROBLEM
],
columns: [
search.createColumn({
name: "internalid",
label: "ID"
})
]
});
Filter expecting numeric value was removed, as non-numeric value 'Estonia' was provided
Any idea how to get this work?
You can try using help id: 63281, 82791
.>Get Country IDs and Country Names on SuiteScript
.>Use SuiteScript to Generate a List/File of All Country and State Names/Abbreviations
Related
I want to search if a keyword present in any of the fields in documents. some field values are objects.so it is also needed to check whether the keyword present inside that object also.
so I came across the following solution.
collections: products(having companyId as foreign key), company
mongoQuery
db.products.aggregate([{$match:{$text:{$search:"hello"}}},{$lookup:{from:"companies",localField:"companyId",foreignField:"_id",as:"company"}},{$unwind:"$company"}])
result
`
[
{
_id: ObjectId("63832de4e9dbcd9b2942ded7"),
companyId: [ ObjectId("6383048ae9dbcd9b2942dece") ],
title: 'hello world',
imageUrl: 'https://drive.google.com/file/image',
company: {
_id: ObjectId("6383048ae9dbcd9b2942dece"),
name: 'name1',
url: 'name1.com'
}
}
]
`
But problem is that i have another document where 'company.name' having value "hello".By using above query it doesn't return the second document.How can i solve this problem?
$or is your correct approach: https://www.mongodb.com/docs/manual/reference/operator/query/or/
Just use it with .find as example links shows and you will get an array of documents.
Hey guys i have two collections of "ORDERS" and "DRIVERS"
The ORDER collection is like
_id:5f8e7d8084378609b2dca93f
user_id:"5f8465a777b1814c588521e2"
price:96
city:"Mumbai City"
totalCost:96
so here city comes from google map, means i just drag the marker in my google maps and it sets the city as "Mumbai City"
and the DRIVER collection is like
_id:5f84485b0933073435cdee30
name:"Ratnabh Kumar Rai"
password:"$2b$10$MSxPYKkdn7HbpjoYCgbg1.RewN5Q26CFxSVLrFqR6e.J4jSNd7G5."
city:[ 'Mumbai', 'Ahmednagar', 'Yavatmal', 'Warud', 'Umred' ]
status:1
where city is manually assigned by the admin
what i want is wanna filter out that whether city from my ORDERS collection is in the DRIVERS collection or not....what i was doing until now was
let driverCity = data.city; /////city is the driver city which i am sending from front-end/////
so now driverCity=[ 'Mumbai', 'Ahmednagar', 'Yavatmal', 'Warud',
'Umred' ] and order city is still "Mumbai City"
let doc = await db
.collection("orders")
.find({
$and: [
{ city: { $in: driverCity } },
],
})
.toArray();
but it checks for the exact element so if google would have set "Mumbai" instead of "Mumbai City" this would be perfect but now as i have "Mumbai city" what am i supposed to do ?
Anyway i could check if any string from driverCity array is present in order city or any other way ?
You can use a RegExp (a regular expression) to match partial data in Mongo.
let doc = await db
.collection("orders")
.find({
$and: [
{ city: new RegExp(driverCity,'i') }, // 'i' is for ignore case
],
})
.toArray();
You can also use regexp wildcards and control chars in case you want better control of what you're searching:
new RegExp(`^${driverCity}`,'i') // search cities starting with "Mumbai"
Or even add an optional City string in your search:
new RegExp(`^${driverCity}(\\s+City)$`,'i') // search either Mumbai or Mumbai City
Anyway, regex searches are considerably slower and could lead to imprecise results, so consider modifying the data that comes from Google before inserting it into the orders collection in a way that it will later match your driver-order searches.
i need to pick a field from item master record. The item type is sometimes service item and sometimes itemgroup. There is some issue in record 'type' and 'id'. Please help.
My Code:
var govFeeFieldInside = search.lookupFields({
type: search.Type.ITEM,
id: item_,
columns:
[
'custitem2'//govFeeInItemMaster
]
});
lookupFields is only for body-level fields. To retrieve sublist data from any record, you will need to either perform a search or load the record.
I am trying to find out if I can pull a sublist without loading the main record. It seems wasteful when all I need is the sublist and I don't get the sublist back with a saved search. search.lookupFields only gives access to body fields which is so very close. I would like to pull a specific sublist is this possible? Thanks in advance for any help.
Sublists in NetSuite are actually records which are linked through some field(like joins in SQL). Being said that, you can use join property in search.createFilter, search.createColumn, searchResult.getValue etc and pass the common field to it while the name parameter will contain the fieldId of the field that you want to fetch the value of.
Eg to fetch item data from salesorder, you can run the following code
var salesOrderSearchResult = search.create({
type: 'transaction,
filters: search.createFilter({
name: 'internalid',
join: 'item',
operator: 'is',
values: ITEM_INTERNAL_ID
}),
columns: search.createColumn({ name: 'itemid', join: 'item' })
}).run().getRange({ start: 0, end: 100 });
// to fetch results
salesOrderSearchResult.forEach(function (searchResult) {
var itemId = searchResult.getValue({ name: 'itemId' ,join: 'item' });
})
I'm using the FourSquare venue search, and specifying the categoryId to filter by category. But I keep getting items from other categories.
For example, when I specify the Food category, the results include private homes. When I specifying the Professional & Other Places category, the results include roads.
I've retrieved the FourSquare category hierachy. Here're the relevant items:
Professional & Other Places: 4d4b7105d754a06375d81259
Food: 4d4b7105d754a06374d81259
Residence: 4e67e38e036454776db1fb3a
Home (private): 4bf58dd8d48988d103941735
Travel & Transport: 4d4b7105d754a06379d81259
Road: 4bf58dd8d48988d1f9931735
When I send the following request, searching within the Food (4d4b7105d754a06374d81259) category:
venues/search?query=nørrebrogade&intent=browse&ll=55.69434,12.54886&radius=10000&categoryId= 4d4b7105d754a06374d81259
Then the result include a private home (category 4bf58dd8d48988d103941735) as the first item:
id: "4be508d0910020a1ac98d214"
name: "Nørrebrogade"
contact: {}
location: {
isFuzzed: true
lat: 55.68978577050405
lng: 12.550528230660262
distance: 2748
cc: "DK"
state: ""
country: "Denmark"
}
categories: [{
id: "4bf58dd8d48988d103941735"
name: "Home (private)"
pluralName: "Homes (private)"
shortName: "Home"
icon: {
prefix: "https://ss1.4sqi.net/img/categories_v2/building/home_"
suffix: ".png"
}
primary: true
}]
verified: false
stats: {
checkinsCount: 140
usersCount: 52
tipCount: 0
}
specials: {
count: 0
items: []
}
hereNow: {
count: 0
groups: []
}
referralId: "v-1385461452"
I realize that specifying a category will also return items from sub-categories. But Food and
Residence are different top level categories, so why is this result returned?
In the same way, using the categoryId 4d4b7105d754a06375d81259 (Professional & Other Places), returns an item from a different top level category Road (4bf58dd8d48988d1f9931735).
I'm using intent=browse.
I found this question Getting valid data with the Foursquare API category?, which sounds similar, but doesn't contain any solution, except manually filtering the results.
It's likely that you're seeing this because categoryId filtering also matches secondary categories. If you make a venue details request for that venue, you see that it has "Home (private)" set as its primary category (which is reflected in the search result), but you also see that somebody has categorized this as a Falafel and Middle Eastern Restaurant (whether or not this is valid is a question for our community). The top-level Food category was matched on this subcategory.