How to search cases by CompanyId in Netsuite Suitescript 2.0? - netsuite

I can able to search the case by company name
var mySearch = search.create({
type: search.Type.SUPPORT_CASE,
columns: [{
name: 'title'
}, {
name: 'company'
}],
filters: [{
name: 'company',
operator: 'is',
values: 'Test'
}]
});
return mySearch.run({
ld: mySearch.id
}).getRange({
start: 0,
end: 1000
});
But I am not able to search case by company id.
companyId is 115
Below are not working
i)
filters: [{
name: 'company',
operator: 'is',
values: 115
}]
ii)
filters: [{
name: 'companyid',
operator: 'is',
values: 115
}]

According to the Case schema company is a Text filter, meaning you would have to provide it with the precise Name of the company, not the internal ID.
Instead you may want to use the customer.internalid joined filter to provide the internal ID. Also, Internal ID fields are nearly always Select fields, meaning they do not accept the is operator, but instead require the anyof or noneof operator.
You can find the valid operators by field type on the Help page titled Search Operators

First, you can try this :
var supportcaseSearchObj = search.create({
type: "supportcase",
filters:
[
["company.internalid","anyof","100"]
],
columns:
[
search.createColumn({
name: "casenumber",
sort: search.Sort.ASC
}),
"title",
"company",
"contact",
"stage",
"status",
"profile",
"startdate",
"createddate",
"category",
"assigned",
"priority"
]
});
Second : how did I get this ? The answer is hint that will make your life easier :
Install the "NetSuite Saved Search Code Export" chrome plugin.
In Netsuite UI, create your saved search (it is always easier that doing it in code).
After saving the search, open it again for edition.
At the top right corner (near list, search menu in the netsuite page), you will see a link "Export as script" : click on it and you will get your code ;)
If you can not install the chrome plugin :
In Netsuite UI, create your saved search (it is always easier that doing it in code).
In your code, load your saved search
Add a log.debug to show the [loadedesearchVar].filters
You can then copy what you will see in the log to use it as your search filters.
Good luck!

Related

Get the list of records to which a file is Attached

I want to get the list of all the records(whether it may be entity record, transaction record or any other record) to which a single file is attached from the file cabinet in Netsuite. Is there any way to do so??
I believe the saved search approach is the best way. But I don't think you can do it by creating a Document saved search. I think you have to create an entity saved search, a transaction saved search, etc, and then put in the file ID into the criteria filter's "File fields..." internal ID field.
Having to create a saved search for each record type is a bit clunky, but if you have SuiteScript experience it helps if you have the "NetSuite: Search Export" chrome extension. You can create one saved search on the front-end and then use that extension to "Export as script" the one saved search and try to reproduce its criteria for each record type that you are interested in linking to the one file.
Let suppose you want to search a file for a Salesorder. You need to do it separate for entity, transaction etc, remove type and id for all records search.
Here is an example in 2.0.
var salesorderSearchObj = search.create({
type: "salesorder",
filters:
[
["type","anyof","SalesOrd"],
"AND",
["internalid","anyof",12345],
"AND",
["taxline","is","F"],
"AND",
["cogs","is","F"],
"AND",
["shipping","is","F"],
"AND",
["mainline","is","T"]
],
columns:
[
search.createColumn({
name: "trandate",
sort: search.Sort.ASC,
label: "Date"
}),
search.createColumn({
name: "internalid",
join: "file",
label: "Internal ID"
}),
search.createColumn({
name: "url",
join: "file",
label: "URL"
}),
search.createColumn({
name: "url",
join: "lineFile",
label: "URL"
})
]
});
var searchResultCount = salesorderSearchObj.runPaged().count;
salesorderSearchObj.run().each(function(result){
var fileId = result.getValue({
name: "internalid",
join: "file",
label: "Internal ID"
});
var fileObj = file.load({id: fileId});
return true;
});

Elasticsearch 6.2 - Completion Suggester for long texts

I want to be able to search and suggest through long texts.
Below is my input string:
Clinical Support Specialist Medical Staff
If I search for clin or supp or spe or med or st it should give the results as the above string.
Also searches could be like clinical sup or specialist medi
Below is the mappings I create for the field:
description: {
type: 'completion',
analyzer: 'simple',
preserve_separators: true,
preserve_position_increments: true,
contexts: {
name: 'company',
type: 'category',
path: 'company',
}
}
And below is the search body:
descSuggestor: {
prefix: searchTerm,
completion: {
field: 'description'
}
}
Your question does not specify the elastic search version, or the environment you are trying to write your search query. However, you would be able to do that with regular expression in Kibana. For example, in the Dev tools of Kibana, you could write something like:
GET utilization_aggregation_2018/_search
{
"query": {
"regexp" : {"name": "supp.*"}
}
}
Hope this helps!

Access Transaction Type in SuiteScript 2.0

I'm new to Netsuite and SuiteScripting. I am trying to create a Search in SuiteScript 2.0 that will display Inventory Items based on a few filters. One of the filters I am trying to use is in the items related records. I am able to do this in Netsuite's saved search but need to be able to do it in SuiteScript.
Creating the search criteria in Netsuite:
The Transaction: Type is Sales Order is what I am trying to copy in SuiteScript.
I tried using the Join tag but that does not seems to change my results at all.
The following code will run but does not change the results.
search.createFilter({
name: "internalid",
join: "transaction",
operator: search.Operator.IS,
values: 'salesorder'}) ]
If I try to change Name: to "type" it runs but gives no results.
search.createFilter({
name: "type",
join: "transaction",
operator: search.Operator.IS,
values: 'salesorder'}) ]
Any help is appreciated.
I was able to resolve the issue. Using a different syntax for the search. I was able to export the search criteria as SuiteScript with a browser tool.
var SearchResults = search.create({
type: search.Type.INVENTORY_ITEM,
filters:
[
["quantityonhand","greaterthan","0"],
"AND",
["isinactive","is","F"],
"AND",
["type","anyof","InvtPart"],
"AND",
["modified","onorbefore","3/3/2018 12:00 am","3/17/2018 11:59 pm"],
"AND",
["transaction.type","anyof","SalesOrd"]
],
columns:["itemid", "internalid", "displayname", "quantityonHand", "isinactive"]
}).run().getRange({start: 0, end: 1000});

How to get the Vendor Name column from purchase order in suitescript 2.0

Disclaimer: I'm a NetSuite newbie.
I need to return both the item and the vendor name for all items in a purchase order. I Googled around and found this search.
The search works as desired.
var purchaseorderSearchObj = search.create({
type: "purchaseorder",
filters: [
["type","anyof","PurchOrd"], 'and',
['mainline','is','F'],'and',
['tranId','is',targetTranId.toString()]
],
columns: [
search.createColumn(
{ name: "itemid", join: "item" }
)
]
});
Now I need to add the Vendor Name column to the search.
I look for the purchase order objects description, and found it here (http://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2017_1/script/record/purchaseorder.html).
I then try to modify the search by doing something like:
columns: [
search.createColumn(
{name: "itemid",join: "item"},
{name: "vendorname", join "item"})
]
. . . with no good result. I've tried {name: "vendorname"}, { name: "vendorname", join: "vendor"}, and other permutations.
What properties should I use for the 'columns' attribute to return item and vendorname?
How do I learn which columns need joining?
You need to call search.createColumn() again to create a new column:
columns: [
search.createColumn(
{name: "itemid",join: "item"}),
search.createColumn(
{name: "vendorname", join: "item"})
]

Stratio Lucene for Cassandra

I am newbie to Lucene. Just started. I have a few basic questions:
How to view all the indexes that are created using Stratio Lucene ?
How to delete indexes created using Stratio Lucene ?
What is the difference between
fields: {
fld_1: {type: "string"},
fld_2: {type: "text"}
}
type: "string" and type: "text"
The reason I ask for the difference is because I ran in to an error when trying to create my very first lucene index. My column in Cassandra is something like this: 'fld_1 text', but when I tried to create and index on fld_1 like above it threw an exception
ConfigurationException: 'schema' is invalid : Unparseable JSON schema: Unexpected character ('}' (code 125)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name
at [Source: {
fields: {
The Lucene index script:
CREATE CUSTOM INDEX lucene_index ON testTable ()
USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
'refresh_seconds': '1',
'schema': '{
fields: {
fld_1: {type: "string"},
fld_2: {type: "string"},
id: {type: "integer"},
test_timestamp: {type: "date", pattern: "yyyy/MM/dd HH:mm:ss"}
}
}'
};
Thanks!
First : You can't view only the Stratio Lucene Index, below query will show you all the index
SELECT * FROM system."IndexInfo";
Second : You can delete index with DROP INDEX index_name command. i.e
DROP INDEX test;
Third : In Stratio Lucene Index, string is a not-analyzed text value and text is a language-aware text value analyzed according to the specified analyzer.
Which means that if you specify a field as string it will directly index and queried. But if you use text then it will first analyzed by your specified analyzer, default is default_analyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) then index and queried.
Edited :
You have to first create a text field in cassandra then specified it when creating index.
Example :
ALTER TABLE testtable ADD lucene text;
CREATE CUSTOM INDEX lucene_index ON testTable (lucene) USING 'com.stratio.cassandra.lucene.Index'
WITH OPTIONS = {
'refresh_seconds': '1',
'schema': '{
fields: {
fld_1: {type: "string"},
fld_2: {type: "string"},
id: {type: "integer"},
test_timestamp: {type: "date", pattern: "yyyy/MM/dd HH:mm:ss"}
}
}'
};
For more : https://github.com/Stratio/cassandra-lucene-index/blob/branch-3.0.13/doc/documentation.rst#text-mapper

Resources