Object method approach to .setLeftParens .setRightParens & .setOr in SuiteScript 2.X - suitescript2.0

I'm searching for the equivalent in SS 2.X of this:
new nlobjSearchFilter('postingperiod', 'transaction', 'is', period).setLeftParens(1).setOr(true)
This seems to not work:
searchMod.createFilter({
name: 'postingperiod',
operator: searchMod.Operator.IS,
join: 'transaction',
values: period
}).setLeftParens(1).setOr(true);

You can use filter expressions (Search.filterExpression) to group filters using and or or.
The sample below is from the Help Center:
search.create({
type: search.Type.CUSTOMER,
filters: [
['email', search.Operator.STARTSWITH, 'kwolff'],
'and',
[
['id', search.Operator.EQUALTO, 107], 'or',
['id', search.Operator.EQUALTO, 2508]
]
]
});

Related

GROQ: Query one-to-many relationship with parameter as query input

I have a blog built in NextJS, backed by Sanity. I want to start tagging posts with tags/categories.
Each post may have many categories.
Category is a reference on post:
defineField({
name: 'category',
title: 'Category',
type: 'array',
of: [
{
type: 'reference',
to: [
{
type: 'category',
},
],
},
],
}),
This is my GROQ query:
*[_type == "post" && count((category[]->slug.current)[# in ['dogs']]) > 0] {
_id,
title,
date,
excerpt,
coverImage,
"slug": slug.current,
"author": author->{name, picture},
"categories": category[]-> {name, slug}
}
The above works, when it is hardcoded, but swapping out 'dogs' with $slug for example will cause the query to fail. (Where $slug is a param provided)
*[_type == "post" && count((category[]->slug.current)[# in [$slug]]) > 0]
{
$slug: 'travel'
}
How do I make the above dynamic?
Returns all documents that are storefronts // within 10 miles of the user-provided currentLocation parameter ; // For a given $currentLocation geopoint
I can't believe it. Rookie mistake. I needed to pay more attention in the Sanity IDE. (To be fair there was a UI bug that hid the actual issue)
The param should not contain the $. E.g the following works in the GROQ IDE.
{
slug: 'travel'
}

Populate data with custom function

How can I add custom filter options AND all the other data to a custom function?
Below is my code. I would like to have Yes and No filters, but also filters for all the other values in the column.
{column_number: creator_index,
filter_type: 'custom_func',
custom_func: Creator_Filter_Function,
data: [
{value: 'yes', label: 'Yes'},
{value: 'no', label: 'No'},
],
filter_default_label: "All"
},
You should use the append_data_to_table_data option for your filter
From docs:
append_data_to_table_data
Required: false
Type: string
Default value: undefined
Possible values: before / sorted
Description: Use 'before' to place your data array before the values that yadcf grabs from the table
use 'sorted' to place the data array sorted along with the values that yadcf grabs from the table
Note: 'sorted' option will have affect only if you data is an array of primitives (not objects)
So eventually your code will look like this
{
append_data_to_table_data: 'before',
column_number: creator_index,
filter_type: 'custom_func',
custom_func: Creator_Filter_Function,
data: [
{value: 'yes', label: 'Yes'},
{value: 'no', label: 'No'},
],
filter_default_label: "All"
},

DataTables Enable Select Capability on Specified colums

I'm using a plugin to create a data table with single row select capability such that when I click anywhere in the row, it links to another page in my web app. I need help figuring out how to disable the select capability on the first column of every row. I've tried using css rules but either they do not work or they are applied to columns other than the first.
Table declaration:
var locationTable = $('#locationTable').DataTable({
dom: 'Brtip',
buttons: [
'excel'
],
select: {
style: 'single'
//selector: ':not(:first-child)'
//selector: ':not(td:nth-of-type(1))'
},
processing: true,
serverSide: true,
ajax: "/locationData",
length: 10,
ordering: false,
"lengthChange": false,
//sDom : '<"top">lrtip',
columns: [
{data: 'locationname'},
{data: 'address1'},
{data: 'address2'},
{data: 'city'},
{data: 'state'},
{data: 'zipcode'},
{data: 'phone'},
{data: 'fax'}
]
});
My attempt to configure selection on every column (of every row) except the first:
//locationTable.select.selector(':not(tr>td:nth-child(1))');
locationTable.select.selector('tr>td:nth-child(2)');
demo
Solution: Add a CSS rule for each column you wish to enable select capability. In the example below, I wish to have select capability on all columns except the first.
select: {
style: 'single',
selector: 'tr>td:nth-child(2), tr>td:nth-child(3), tr>td:nth-child(4), tr>td:nth-child(5), tr>td:nth-child(6), tr>td:nth-child(7), tr>td:nth-child(8), tr>td:nth-child(9)'
}

Best way to parse a query like string

So I am building a query like search component for a web application I am working on, similar to the search bar seen for Jira's advance issues search:
https://jira.atlassian.com/browse/WBS-167?jql=status%20%3D%20Accepted
The search is basically very similar to the WHERE statement in SQL but only supporting selected set of comparison operators (for instance I don't plan on supporting the between comparison operator). First thing that came to mind is to use regex but I hear that SQL is the 3rd worst thing to parse with regex.
As an example, this would probably be a complex query I would want to be able to parse:
firstName = 'john' OR (lastName = 'doe' AND (status IN (1,3,5) OR type NOT IN (2, 4, 6)) AND username CONTAINS 'd' AND (type = 1 OR status = 2)
and would would want the result of parsing this string to looks something like this:
[{
field: 'firstName',
comparison: '=',
value: 'john'
}, {
connector: 'OR',
items: [{
field: 'lastName',
comparison: '=',
value: 'doe'
}, {
connector: 'AND',
items: [{
field: 'status',
comparison: 'IN',
value: [1,3,5]
}, {
connector: 'OR',
field: 'type',
comparison: 'NOT IN',
value: [2,4,6]
}]
}]
}, {
connector: 'AND',
field: 'username',
comparison: 'CONTAINS',
value: 'd'
}, {
connector: 'AND',
items: [{
field: 'type',
comparison: '=',
value: 1
}, {
connector: 'OR',
field: 'status',
comparison: '=',
value: 2
}]
}]
If regex is a bad choice (and trying to work with regex for a couple of hours did not produce any good results), what is the best why to try to parse this type of string?
It looks like you are developing a small and simple language. As ebyrod said you should use a grammar-based parser instead of regex. Lex and Yacc are great and easy tools for the job. Depending on the language you are using, there are different alternatives.
Take a look at this.
As you can see, you will need to define all the supported operations that can appear on your input. This is done on the Lex file. Then you will need to define your syntax structure (grammar) and the last step is composing your output string.

What is Datastructure of LazyTreeGridStoreModel?

I am working with LazyTreeGridStoreModel .
And need to form a json datastructure with child parent relationship that can support LazyTreeGridStoreModel.
I saw the sample given in the dojo site but couldn't find the relationship between parent child.The below sample provided on dojo site.
data = {
identifier: 'id',
label: 'name',
items: [
{id: 'AF', name:'Africa', children: true},
{id: 'EG', name:'Egypt' , children: false},
{id: 'KE', name:'Kenya',
children:[
{id: 'Nairobi', name:'Nairobi', type:'city'},
{id: 'Mombasa', name:'Mombasa', type:'city'}
]
},
...
]
}
Where i can declare the children of
{id: 'AF', name:'Africa', children: true},
Abhisek
You will need to implement the mechanism in your JSON data and in your datastore.
Typically, an attribute is added to the JSON data to indicate the parent-id.
For example:
{id: 'EG', name:'Egypt' , children: false, '$ref': 'AF'}
Here '$ref' is referring to the parent's id for this child.
The LazyTreeGridStoreModel will call store.fetch() with a query object {parentId: value} and you can extend your store (QRS for example) and implement isItemLoaded(), loadItem(), and getValues() to return the children items appropriate for your data
The following URL has a nice example on how to implement this with queryreadstore:
http://www.ibm.com/developerworks/web/library/wa-dojotreegrid/index.html
Also see:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_treegrid_model_lazy.html
View the source to see how the children in the JSON data are using a "$ref" attribute to indicate their parent