How to filter a view by id field in CouchDB? - couchdb

I have a view which outputs the following JSON:
{"total_rows":26,"offset":0,"rows":[
{"id":"SIP-13","key":[1506146852518,"SIP-13"],"value":{"clientId":"CLIENT-2","orderCount":2}},
{"id":"SIP-12","key":[1506147024308,"SIP-12"],"value":{"orderCount":1}},
{"id":"SIP-14","key":[1506159901457,"SIP-14"],"value":{"orderCount":1}},
{"id":"SIP-15","key":[1506161053712,"SIP-15"],"value":{"clientId":"CLIENT-2","orderCount":2}},
{"id":"SIP-16","key":[1506448298050,"SIP-16"],"value":{"clientId":"CLIENT-3","orderCount":1}}
]}
...and I want to get the row with id: "SIP-15" here. How can I do that?

You have to use complex keys. The first field indexed can be anything and the second must be SIP-15.
Query :
?startkey=[null,"SIP-15"]&endkey=[{},"SIP-15"]

Related

Retrieve OptionSet from Dynamics Web API MetaData

I'm trying to retrieve the option set values (localized labels and integer Ids) for a specific field on a specific entity. Below is the code that I am using, but every time I execute it, it brings back ALL optionsets that are currently in my system (about 800+) and I don't want to do that.
EntityDefinitions(LogicalName='#MY_ENTITY#')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '#MY_ENTITY_ATTRIBUTE#'&$expand=OptionSet
maybe this can help,
/api/data/v9.1/ENTITY(guid OR Filter)?$select=ATTRIBUTE1,ATTRIBUTE2
include header:
{
"Prefer": "odata.include-annotations=OData.Community.Display.V1.FormattedValue"
}
this gives us a response like this:
{
"ATTRIBUTE1#OData.Community.Display.V1.FormattedValue": "Person",
"ATTRIBUTE1": 1,
"ATTRIBUTE2#OData.Community.Display.V1.FormattedValue": "Company",
"ATTRIBUTE2": 2
}
I'm using the stringmap entity to retrieve the optionsets.
This represents the optionsets as a simple table on which you can filter in the query
For example by calling:
/stringmaps?$filter=(objecttypecode eq 'contacts')
you get only the optionsets which are use in the contact entity. You can also filter on attribute name, the option value (field value) or option id (field attributevalue).

How do I do a joined lookup with search.lookupFields()?

I'm trying to get some information about an item, including the item's subsidiary's logo, which naturally requires joining the item to the subsidiary.
The documentation for search.lookupFields says:
You can use joined-field lookups with this method, with the following syntax:
join_id.field_name
So, I duly request the fields I want, including a join on subsidiary:
require(['N/search'], function(search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary.logo'],
});
log.debug(item);
});
itemid and displayname are fine, but when I try to join another record I get this error:
{
"type":"error.SuiteScriptError",
"name":"SSS_INVALID_SRCH_COLUMN_JOIN",
"message":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"stack":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"cause":{
"type":"internal error",
"code":"SSS_INVALID_SRCH_COLUMN_JOIN",
"details":"An nlobjSearchColumn contains an invalid column join ID, or is not in proper syntax: logo.",
"userEvent":null,
"stackTrace":["doLookupFields(N/search/searchUtil.js)","<anonymous>(adhoc$-1$debugger.user:2)","<anonymous>(adhoc$-1$debugger.user:1)"],
"notifyOff":false
},
"id":"",
"notifyOff":false,
"userFacing":false
}
This seems to happen no matter which record and field I try to join. What am I missing?
Although you can return results from multi-select fields, you cannot join to fields on records referenced by multi-select fields (which the subsidiary field on the item record is). Also, you cannot search the logo field on the subsidiary record (not listed in Search Columns under Subsidiary in the NetSuite Records Browser).
This means you have to load the Subsidiary record to get the logo field. In other words:
require(['N/record', 'N/search'], function(record, search) {
var item = search.lookupFields({
type: search.Type.ITEM,
id: 2086,
columns: ['itemid', 'displayname', 'subsidiary'],
});
var subID = item.subsidiary[0].value; //internal id of *first* subsidiary
var subRec = record.load({
type: record.Type.SUBSIDIARY,
id: subID
});
var logo = subRec.getText('logo'); //gets the file name - use getValue to get its ID instead
});
Note that if multiple subsidiaries are set on the item, this only gets the values for the first one. You could iterate through the item.subsidiary result to handle values for multiple subsidiaries if required.
I believe you can't access to the subsidiary record from a lookupfield, you should do a proper search.
https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2018_2/script/record/item.html
You can only join to tables allowed in the Item search object. Try looking for "Subsidiary..." in the Search Results tab within the UI. It's not there. Use the Schema Browser to determine what fields and joins are available.
You cannot think of a NetSuite search as you would any regular SQL search. You have to be cognizant of which fields and which joins can be utilized via the search object.
As people have mentioned, the subsidiary is not a join field available from the item record, one way to achieve what you are trying to do is:
Make a lookup to get the internal id of the subsidiary belonging to the desired item.
Then make a lookup to get the internal id of the logo image (file cabinet image) belonging to the previous subsidiary.
Make another lookup/load the image file to get the URL of the image/logo
You can try to combine the above steps in a single saved search but I think you might need to load the image file to get the URL.
This won't answer your question, but this may help out in the future. The records browser shows everything that you can search and join on, columns and filters, and field IDs. Very useful when building out searches.
NetSuite Records Browser - 2018.2

How to filter on view using complex query

I am trying to filter on a view which emits bookName and bookItem.
emit([doc.basicInfo.bookName,doc.basicInfo.bookItem], 1);
it gives me below result without any query:
{"total_rows”:10,”offset":0,"rows":[
{"id":"d4e5548fb01e6e2c559e702fe7b138ad","key":["correctaccouts","billing"],"value":1},
{"id":"863c46c645b6344719a08231606f2a7d","key":["credeaccount","system"],"value":1},
{"id":"68d39e64c406127960dc735e8167eee3","key":["credeaccount11","system"],"value":1},
{"id":"1ab4d31588d76a42e85b526a316074de","key":["mayankamazon","billing"],"value":1},
{"id":"3204f5db5df91886373f95995ce09a2d","key":["mayankazure","asset"],"value":1},
{"id":"452c040048fb2b779205b3785615d368","key":["mayankmaaa","system"],"value":1},
{"id":"23f01f7bc60c2c8f24f6b741584a69fa","key":["TEST_AWS_Delete212sss12","asset"],"value":1},
{"id":"f0093f474e0d50f046b9fdc9145bdc91","key":["vijeth-myteam111115555555","asset"],"value":1},
{"id":"c3bce8dd1482d841f445fbd617ba1db7","key":["vijeth-myteam11111555sss5555","asset"],"value":1},
{"id":"347479ba91696b73f4a57252cd00a358","key":["vijeth-myteamOnly","asset"],"value":1}
]}
Now I am trying to query on it using complex keys:
satrtkey=[{},"asset"]&endkey=[{},"asset"]
It should return me:
{"total_rows”:5,”offset":0,"rows":[
{"id":"3204f5db5df91886373f95995ce09a2d","key":["mayankazure","asset"],"value":1},
{"id":"23f01f7bc60c2c8f24f6b741584a69fa","key":["TEST_AWS_Delete212sss12","asset"],"value":1},
{"id":"f0093f474e0d50f046b9fdc9145bdc91","key":["vijeth-myteam111115555555","asset"],"value":1},
{"id":"c3bce8dd1482d841f445fbd617ba1db7","key":["vijeth-myteam11111555sss5555","asset"],"value":1},
{"id":"347479ba91696b73f4a57252cd00a358","key":["vijeth-myteamOnly","asset"],"value":1}
]}
But it still gives me all 10 records. I want to filter only records of type "asset".
To use key ranges, you must narrow down your research starting with the left fields to the right fields.
For example, if your key would be: [doc.basicInfo.bookItem,doc.basicInfo.bookName]
You could search with start_key=["asset",null]&end_key=["asset",{}]
Also, your current query is equivalent to key=[{},"asset"]. Instead, you should have tried: start_key=[null,"asset"]&end_key=[{},"asset"] but it should not work.
Example
View:
function (doc) {
emit([doc.basicInfo.bookItem,doc.basicInfo.bookName], 1);
}
Query:
http://localhost:5984/<db>/_design/<design_name>/_view/<view_name>?include_docs=true&inclusive_end=true&start_key=%5B%22asset%22%2Cnull%5D&end_key=%5B%22asset%22%2C%7B%7D%5D

I want to do a solr search to see if a dynamic field exists or not

I want to do a solr search to see if a dynamic field exists or not.
Example:
Doc 1 {
Id: 111
Name: good
Tag_100_is: lsdkl
}
Doc 1 {
Id: 2
Name: not good
}
I want a query to retrieve doc 1.
Thank you in advance.
To query for whether a field exists or not, use field:[* TO *]. So in this case, you should get the document you want by using the query Tag_100_is:[* TO *].
If you want to get the document without the field, you'll have to invert the query (we start with : which are "all documents", then remove the documents that have the field):
q=*:* -Tag_100_is:[* TO *]

OrientDB: containsall operator

I have collection of documents. Document have a field which value is an array of maps (for example: map with one field name). Structure is like that:
{
arrayfield: [
{
name: "value1",
},
{
name: "value2",
}
]
}
I want to fetch documents whose arrayfieds all maps contain values from specified array. Documentation says that I can use containsall operator. I use it in this way:
select from SomeCollection where arrayfiled containsall (name in ['value1','value2'])
But this construction always returns empty result. Where I do mistake? Thanks.
PS: If my question not understandable, I can post more detailed example of the collection and and a result which I want to receive.
Found a solution to solve my issue without containsAll:
select from SomeCollection where not (arrayfield contains (fname not in ["value1", "value2"]))
Try the following query
select from SomeCollection where arrayfiled.name contains "value1" and arrayfiled.name contains "value2"

Resources