How to search for customer internal id using customer name? Suitescript 2.0 - suitescript2.0

As titled, how to search Netsuite internal id by other fields (ex: customer name)? Thanks

You can use the following to fetch customer-internalid
var customerSearchResult = search.create({
type: 'customer',
filters: [{ name: 'entityid', operator: 'is', values: CUSTOMER_NAME }]
}).run().getRange({ start: 0, end: 1 });
var customerInternalId = customerSearchResult[0].id;
where, entityid is id of customer name field and CUSTOMER_NAME is customer name that you want to search

Related

Sequlize Query get last added value

I am using Sequlize. I have a table status_config in this table I have a column create_time as timestamp( 2021-06-02 12:04:52.293977). Now I need to query on this table and get the latest value created on this table.
status_config.findOne({ where: created_time **need to implement here to get last added value})
We can use order by [['createdAt', 'desc']]
let last_status_config = await status_config.findOne({
order:[['createdAt', 'desc']]
});
console.log(JSON.parse(JSON.stringify(last_status_config)))
Output
{ id: 19, name: 'test_last', password: null, confirmation: null }

Many to many with pivot data to dgraph using graphql schema

I have the bellow many to many relation using a relational DB and I want to transition this to the dgraph DB.
This relation has also extra columns in the pivot table: products_stores like price, disc_price.
I have the bellow dgraph schema using graphql:
type Product {
id: ID!
name: String! #id
slug: String! #id
image: String
created_at: DateTime!
updated_at: DateTime!
stores: [Store] #hasInverse(field: products)
}
type Store {
id: ID!
name: String! #id
logo: String
products: [Product] #hasInverse(field: stores)
created_at: DateTime!
updated_at: DateTime!
}
I am newbie to graph databases and I don't know how to define these extra pivot columns.
Any help would be greatly appreciated.
To model a pivot table that is only a linking pivot table holding no additional information, then you model it as you did above. However, if your pivot table contains additional information regarding the relationship, then you will need to model it with an intermediate linking type. Almost the same idea as above. I prefer these linking types to have a name describing the link. For instance I named it in this case Stock but that name could be anything you want it to be. I also prefer camelCase for field names so my example reflects this preference as well. (I added some search directives too)
type Product {
id: ID!
name: String! #id
slug: String! #id
image: String
createdAt: DateTime! #search
updatedAt: DateTime! #search
stock: [Stock] #hasInverse(field: product)
}
type Store {
id: ID!
name: String! #id
logo: String
stock: [Stock] #hasInverse(field: store)
createdAt: DateTime! #search
updatedAt: DateTime! #search
}
type Stock {
id: ID!
store: Store!
product: Product!
name: String! #id
price: Float! #search
originLink: String
discPrice: Float #search
}
The hasInverse directive is only required on one edge of the inverse relationship, if you want to for readability you can define it on both ends without any side effects
This model allows you to query many common use cases very simply without needing to do additional join statements like you are probably use to in sql. And the best part about Dgraph is that all of these queries and mutations are generated for you so you don't have to write any resolvers! Here is one example of finding all the items in a store between a certain price range:
query ($storeName: String, $minPrice: Float!, $maxPrice: Float!) {
getStore(name: $storeName) {
id
name
stock(filter: { price: { between: { min: $minPrice, max: $maxPrice } } }) {
id
name
price
product {
id
name
slug
image
}
}
}
}
For a query to find only specific product names in a specific store, then use the cascade directive to remove the undesired Stock nodes (until Dgraph finished nested filters RFC in progress)
query ($storeName: String, $productIDs: [ID!]!) {
getStore(name: $storeName) {
id
name
stock #cascade(fields:["product"]) {
id
name
price
product(filter: { id: $productIDs }) #cascade(fields:["id"]) {
id
name
slug
image
}
}
}
}

Looping Through a Group in Suitescript 2.0

I am passing sales orders grouped by item into a function. I need to load the sales orders to modify the sales order record that it has already been processed. How would I go about getting all sales orders grouped under the item?
var itemId = result.getValue({
name: 'item',
summary: 'GROUP'
});
The above code gets me the item id for what the orders in the given result are being grouped by. There could be any number of sales within a single group.
Running a grouped saved search in SuiteScript doesn't give you the ability to "drill down" like you can when running a similar search in the user interface. As soon as you have a summary criteria for any column in a saved search, Netsuite requires that all your columns be summarized. If you want to get the internal IDs for the Sales Orders, then they will have to be returned as a summarized column in your saved search code.
Something like this:
const searchObj = search.create({
type: search.Type.SALES_ORDER,
filters: [
['mainline', 'is', 'F']
//,'AND', any other filters you need...
],
columns: [
search.createColumn({
name: "item",
summary: "GROUP"
}),
search.createColumn({
name: "formula(text)",
summary: "MAX",
formula: "ns_concat({internalid})"
})
]
}).run().each(function(result) {
const itemId = result.getValue({name: "item", summary: "GROUP"})
const salesOrderIds = result.getValue({
name: "formula(text)",
summary: "MAX",
formula: "ns_concat({internalid})"
}).split(',')
return true
})

Select sql query to group by nested json

The data I am getting from select query is something like this
[{
id: 'CB2FD8B7-7E6D-4BF3-8E73-70D41FFBE456',
products: '[{"product_id":"22061DA1-5D64-475A-B36A-140ECFE8D6B7"}]',
falconpay_api_response: null,
dhl_updated_by: null
}, ... ]
What I am doing is fetching orders and then parsing products attribute and extracting product_id and counting the number of time the product_id occured in the number of different json objects.
This would be very time consuming if number of rows to fetch are in thousands and then extracting ids and counting its occurrences.
Is there any effective way to use GROUP by and get directly occurrences of product_id for thousands of rows.
You can use it!
var data = [{
id: 'CB2FD8B7-7E6D-4BF3-8E73-70D41FFBE451',
products: [{"product_id":"22061DA1-5D64-475A-B36A-140ECFE8D6B7"}],
falconpay_api_response: null,
dhl_updated_by: null
},{
id: 'CB2FD8B7-7E6D-4BF3-8E73-70D41FFBE452',
products: [{"product_id":"22061DA1-5D64-475A-B36A-140ECFE8D6B7"},{"product_id":"22061DA1-5D64-475A-B36A-140ECFE8D6K7"}],
falconpay_api_response: null,
dhl_updated_by: null
},{
id: 'CB2FD8B7-7E6D-4BF3-8E73-70D41FFBE453',
products: [{"product_id":"22061DA1-5D64-475A-B36A-140ECFE8D6K7"}],
falconpay_api_response: null,
dhl_updated_by: null
},{
id: 'CB2FD8B7-7E6D-4BF3-8E73-70D41FFBE454',
products: [{"product_id":"22061DA1-5D64-475A-B36A-140ECFE8D6B7"}],
falconpay_api_response: null,
dhl_updated_by: null
}];
var a =[];
data.forEach(function(order){
order.products.forEach(function(product){
if(a[product.product_id] == undefined){
a[product.product_id] = [];
}
a[product.product_id].push(order);
})
});
console.log(a);
Try the following Query (That's only works in JSON data type) :-
SELECT products->>'$.product_id' products,
count(products)
FROM events
GROUP BY products->>'$.product_id';
And Following Link will helpful to you :-
[http://www.mysqltutorial.org/mysql-json/]

Sencha Touch SQL proxy

I am using SQL proxy in my Sencha Touch 2 app and I am able to store and retrieve data offline.
What I cannot do and what the Sencha documentation does not seem to provide is how do I customize the Sencha SQL store.
For eg, to create a SQL based store, I did the following -
Ext.define("MyApp.model.Customer", {
extend: "Ext.data.Model",
config: {
fields: [
{name: 'id', type: 'int'},
{name: 'name', type: 'string'},
{name: 'age', type: 'string'}
],
proxy: {
type: "sql",
database: "MyDb",
}
}
});
1. Now, how do i specify the size of the database ?
2. How do I specify constraints on the fields like unique, primary key etc ?
Say, I have 4 columns in my database :
pid, name, age, phone
I want to have a primary key for multiple fields : (pid, name)
If I was creating a table via SQL query, I would do something like -
CREATE TABLE Persons
(
pid int,
name varchar(255),
age int,
phone int,
primary key (pid,name)
);
Now how do I achieve the same via model ?
3. If I want to interact with the database via SQL query, I do the following -
var query = "SELECT * from CUSTOMER";
var db = openDatabase('MyDb', '1.0', 'MyDb', 2 * 1024 * 1024);
db.transaction(function (tx) {
tx.executeSql(query, [], function (tx, results) {
// do something here
}, null);
});
Is this the best way to do it?