How to source Purchase Orders list in a field in Suitelet (suitescript 2.0)? - suitescript

I need to source list of Purchase Orders in a SELECT field in my suitelet.
I tried this:
var pos = form.addField({ // Purchase order select field
id: 'custpage_selectpos',
type: ui.FieldType.SELECT,
label: 'Select PO',
source: 'purchaseorder'
});
After putting purchaseorder is the source property, all the transactions start being shown in my list field. Any idea how to only source the POs?

Related

How to retrieve only the relation ID, not the whole entity in MikroORM?

I have the following basic test entities:
#Entity()
class Author {
#PrimaryKey()
public id!: number;
#Property()
public name!: string;
}
#Entity()
class Book {
#PrimaryKey()
public id!: number;
#Property()
public title!: string;
#ManyToOne({joinColumn: 'authorID'})
public author!: Author;
}
What i'm trying, is to select only a single Book record, with its 'author', but I care only about its ID, I don't want to actually load the entity.
If I simply call this, it won't work (no author data loaded at all):
em.getRepository(Book).findOne({id: 1}, {fields: ['id', 'title', 'author.id']});
'author.id' doesn't do the trick, the SQL doesn't even contain the 'authorID' field.
If I add 'author' to the fields list as well, it works, author is loaded (only with the ID), but as a separate entity, with a separate, additional SQL statement! That's what I'm trying to avoid.
em.getRepository(Book).findOne({id: 1}, {fields: ['id', 'title', 'author', 'author.id']})
#1. SQL
select `b0`.`id`, `b0`.`title`, `b0`.`authorID` from `book` as `b0` where `b0`.`id` = 1 limit 1
#2. SQL (this wouldn't be neccessary as I want only the ID)
select `a0`.`id` from `author` as `a0` where `a0`.`id` in (2)
--> Result:
Book: { id: 1, title: 'a book', author: { id: 2 } }
The only way I found is to add the specific 'authorID' field too to the Book entity:
#Property()
public authorID!: number;
But, I'd like to avoid introducing these foreign key columns, it would be better to handle through the already existing and used 'author' relation (only by the 'id' property).
Does any solution exists where I could retrieve a relation's ID without generating a 2nd SELECT statement (for the relation), and even avoid introducing the foreign key (next to the already existing relation property)? Would be great to receive through the relation without any extra sql statement.
Thanks in advance.
It is correct behaviour you see the second query, that is how population works, and the fact that you want just a single property from the entity does not change anything, you still populate the relation, and each relation will use its own query to load it. You can use LoadStrategy.JOINED if you want to use a single query. But that would still do a join for that relation, which is not needed for your use case.
Given you only want the FK to be present, you dont need to care about the target entity at all. This should do the trick too:
em.getRepository(Book).findOne(1, {
fields: ['id', 'title', 'author'],
populate: [],
});
This way you say you want those 3 properties to be part of what's selected from the Book entity. You already have the author property, which represents the FK. You will end up with what you want once you serialize such entity. During runtime, you will see entity reference there - an entity with just the PK. It is represented as Ref<Author> when you console.log such entity.
Note that you need that populate: [] there, as otherwise it would be inferred from your fields which contains author property, and that would trigger the full load of it.

Drupal 9 view filter on a boolean type field

Drupal 9
Have content type Article.
Content type Article has a field, called "Need Further Review", of boolean type.
This field is not required, default value FALSE.
The articles has value TRUE, FALSE, NULL for this field.
TRUE: select true
FALSE: select false
NULL: the previous articles still have no value for this field.
Have a view to list articles.
A filter criteria is this field "Need Further Review", and is exposed.
It has options: Any, TRUE, FALSE.
When users select TRUE, it will list articles with TRUE value of this field.
When users select FALSE, it usually lists articles with FALSE value of this field.
Now want to list articles with FALSE and NULL value of this field.
Drupal 9 view query alter
https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php/function/hook_views_query_alter/9.0.x
Use hook_views_query_alter
At the moment you create an Article, the field gets a value, either TRUE or FALSE (default). So your view only needs to have an exposed filter for these values.
It is only when you do a migration without setting the field, you will have no value. Or when you add this field later, when there are already Articles made.
Assuming this is the case, one solution is to set the field on those Articles to FALSE manually through the UI.
When there are too many Articles, and if you are able and willing to do some manual queries in the database, you may add the rows in the database for those Articles with a script, something like this (change to fit your situation, and, of course, make a backup first ;):
<?php
$link = mysqli_connect("localhost", "USERNAME", "PASSW", "DATABASENAME");
if($link) {
// get node id's
$nids = array();
$q_nids = mysqli_query($link, "SELECT `nid`,`type` FROM `node` WHERE `type` = 'article' ORDER BY `nid`");
$n_nids = mysqli_num_rows($q_nids);
if($n_nids!=0) {
while($l_nids = mysqli_fetch_assoc($q_nids)) {
foreach($l_nids as $key => $value) {
// insert missing rows
mysqli_query($link, "
INSERT INTO `TABLENAME`.`field_need_further_review`
(`bundle`,`deleted`,`entity_id`,`revision_id`,`langcode`,`delta`,`field_need_further_review_value`)
VALUES ('".$l_nids['type']."','0','".$l_nids['nid']."','0','nl','0','0');
");
}
}
}
}

Google datastore modelling

I have two entities. Categories and Products. Each product can have many categories and each category can belong to many categories. I would like to be able to return all products and for each one to have all the categories it belongs to and their parent categories. Is datastore a good option for something like this?
example Product response:
{
id: 1,
name: "shoes",
categories: [{
id:1,
ordinal:1
},{
id:2,
ordinal:1
}]
}
I assume you meant 'Datastore' where you wrote 'dataflow'
It depends if you want to query later based on categories or not.
In case you won't need to query based on categories
I'd suggest defining your categories in a model (with the appropriate parent/child relationships) and then adding each category to a product in a LocalStructuredProperty. Datastore will save as a blob but will reconstruct the category entity model when you retrieve the product. You could also add a JsonProperty with a serialized string containing the category structure for each product. For example:
[
0: {
category: 'Electronics',
subcategories: ['Smartphones', 'Telephones', 'Gadgets']
},
1: {
category: 'Apple',
subcategories: ['iPhone']
}
]
Read more about the LocalStructuredProperty and the JsonProperty here (for Python client library).
If you need to query based on categories
Then you should use a StructuredProperty. Create a model to define your categories and their ancestor paths. Then you add one or more categories (along with their parents) to the Product entity when you instantiate it.
The Entity Property Reference in Datastore documentation has a good example of how to implement it (in Python, but also available for other languages). And here's how you filter for StructuredProperty values.

Filter Product Name in RetailProductDiscount Form productLookup ax 2012

I need to add the field of ProductName filterable in the ProductLookup field in retailPeriodicDiscount form. It is strongly connected to EcoResProduct and I can't use any other lookup field or method.
So, I need to add the product name field to productLookup method. Any suggestions how to do it?
For the product name you have to add the field Name of the table EcoResProductTranslation .Add the table as a joined datasource to the query and filter it by the system language.
sysTableLookup.addLookupfield(fieldNum(EcoResProduct, DisplayProductNumber));
sysTableLookup.addLookupfield(fieldNum(EcoResProduct, SearchName));
sysTableLookup.addLookupfield(fieldNum(EcoResProduct, ProductType));
sysTableLookup.addLookupfield(fieldNum(EcoResProductTranslation, Name));
if (_groupMember.Category)
{
query = RetailGroupMemberLineQueryProvider::containedProductsQuery(_groupMember.Category, true /*includesubcategories*/, _dataAreaId);
}
else
{
query = RetailGroupMemberLineQueryProvider::containedProductsQuery(_groupMember.Category, true /*includesubcategories*/, _dataAreaId);
}
// add datasources and join
qbdsProduct = query.dataSourceTable(tableNum(EcoResProduct));
qbdsProductTranslation = qbdsProduct.addDatasource(tableNum(EcoResProductTranslation));
qbdsProduct.relations(true);
// range for system language
qbdsTranslation.addRange(fieldNum(EcoResProductTranslation, LanguageId)).value(SystemParameters::getSystemLanguageId());
sysTableLookup.parmQuery(query);

matching fields in a database, ASP.net (VB)

In a table I have news posts with these fields:
Title
Content
OwnerID
And a users table
ID
Name
Surname
The OwnerID relates to the ID in the users table, how can I get the name of the user who's ID matches the OwnerID?
I'm writing a website in ASP.net (VB).
You would need to join the two tables together like this:
select users.Name
from news inner join users
on OwnerID = ID;
This query has no where clause to filter the results that are returned so this query would return all users who are associated with a news record. If you wanted to find users associated with a specific news record you would need to filter on the news title or content like this:
select users.Name
from news inner join users
on OwnerID = ID
where Title = 'Some Title';

Resources