Is it possible to join two pieces of text together using BQL? I would like to use this in a PXFormula. A typical example would be to for example join name and surname together.
I would suggest you use the BQL Add function, the separator can be a string constant, ex:
private class string0101 : Constant<string>
{
public string0101() : base("0101")
{
}
}
private class string01 : Constant<string>
{
public string01() : base("01")
{
}
}
[PXFormula(typeof(Add<AP1099Year.finYear, string0101>))]
[PXFormula(typeof(Add<AP1099Year.finYear, Add<string01, string01>>))]
The BQL and SQL Equivalents table list BQL Add function as equivalent to SQL Concat function:
Source: BQL and SQL Equivalents
Found it: SmartJoin. This provides functionality to concatenate strings and also include a separator. Just what I need.
Related
I am trying to replicate the following type of SQL query that you can perform in SQL Server...the important part here is the WHERE clause:
Select InventoryCD from InventoryItem WHERE InventoryCD IN ('123123', '154677', '445899', '998766')
It works perfectly using the IN3<> operator and a series of string constants:
i.e. And<InventoryItem.inventoryCD, In3<constantA,constantB,constantC>,
However, I need to be able to do this with an arbitrarily long list of values in an array, and I need to be able to set the values dynamically at runtime.
I'm not sure what type I need to pass in to the IN<> statement in my PXProjection query. I have been playing around with the following approach, but this throws a compiler error.
public class SOSiteStatusFilterExt : PXCacheExtension<SOSiteStatusFilter>
{
public static bool IsActive()
{
return true;
}
public abstract class searchitemsarray : PX.Data.IBqlField
{
}
[PXUnboundDefault()]
public virtual string[] Searchitemsarray { get; set; }
}
I think maybe I need an array of PXString objects? I'm really not sure, and there isn't any documentation that is helpful. Can anyone help?
This shows how to do it with a regular PXSelect: https://asiablog.acumatica.com/2017/11/sql-in-operator-in-bql.html
But I need to be able to pass in the correct type using Select2...
For reference I will post here the example mentioned by Hugues in the comments.
If you need to generate a query with an arbitrary list of values generated at runtime like this:
Select * from InventoryItem InventoryItem
Where InventoryItem.InventoryCD IN ('123123', '154677', '445899', '998766')
Order by InventoryItem.InventoryCD
You would write something like this:
Object[] values = new String[] { "123123", "154677", "445899", "998766" };
InventoryItem item = PXSelect<InventoryItem,
Where<InventoryItem.inventoryCD,
In<Required<InventoryItem.inventoryCD>>>>.Select(Base, values);
Please note that In<> operator is available only with Required<> parameter and you need to pass array of possible values manually to Select(…) method parameters. So you need to fill this array with your list before calling the Select method.
Also, the Required<> parameter should be used only in the BQL statements that are directly executed in the application code. The data views that are queried from the UI will not work if they contain Required<> parameters.
I ended up creating 100 variables and using the BQL OR operator, i.e.
And2<Where<InventoryItem.inventoryCD, Equal<CurrentValue<SOSiteStatusFilterExt.Pagefilter1>>,
Or<InventoryItem.inventoryCD, Equal<CurrentValue<SOSiteStatusFilterExt.Pagefilter2>>,
Or<InventoryItem.inventoryCD, Equal<CurrentValue<SOSiteStatusFilterExt.Pagefilter3>>,
Or<InventoryItem.inventoryCD, Equal<CurrentValue<SOSiteStatusFilterExt.Pagefilter4>>,
etc...etc...
You can then set the value of Pagefilter1, 2, etc inside of the FieldSelecting event for SOSiteStatusFilter.inventory, as an example. The key insight here, which isn't that obvious to the uninitiated in Acumatica, is that all variables parameterized in SQL Server via BQL are nullable. If the variable is null when the query is run, SQL Server automatically disables that variable using a "bit flipping" approach to disable that variable in the SQL procedure call. In normal T-SQL, this would throw an error. But Acumatica's framework handles the case of a NULL field equality by disabling that variable inside the SQL procedure before the equality is evaluated.
Performance with this approach was very good, especially because we are querying on an indexed key field (InventoryCD isn't technically the primary key but it is basically a close second).
I have following json array input -
"results": [
{ "tableName" : "ABC","id":"11"},
{ "tableName" : "ZX","id":"11"},
{ "tableName" : "ABC","id":"11"}
]}
In logic app i have used `` in For_each I'm able to append string successfuly but how to avoid adding already present string ? like above example my current output is -
ABC,ZX,ABC
i want - ABC,ZX
You could use the Array to implement, there is a union function to return a collection that has all the items from the specified collections. It will return a collection without duplicate string. Then use join action to return the string.
Cause the union function must contain two collection at least, so I used two same collections. The expression is like this: union(variables('tablename'),variables('tablename'))
The below is the result.
Hope this could help you.
I've got a field in my DAC where I want to put a selector that looks up the SalesPersons. I know how to do this:
[PXSelector(typeof(SalesPerson.salesPersonCD)
,typeof(SalesPerson.salesPersonCD)
,typeof(SalesPerson.descr))]
My problem is that I want to filter this selector based on the first three characters of the SalesPerson CD, i.e., StartsWith "SSR" or something similar. I know you can use BQL in a selector using the Search<> command, and I know how to set up a constant class, but I'm not sure of the syntax to filter by beginning characters.
Short of creating a custom BQL operator, you can achieve "Starts with" by using the LIKE operator, with the % wildcard at the end. The BQL field you're filtering on could be a DAC property with custom code in the get accessor, which takes your user-entered field and adds the wildcard character at the end, like that:
public abstract class myFieldWildcard : PX.Data.IBqlField { };
[PXString(30, IsUnicode = true)]
public virtual String MyFieldWildcard
{
[PXDependsOnFields(typeof(myField)]
get
{
return MyField + PXDatabase.Provider.SqlDialect.WildcardAnything;
}
}
You'll then be able to use that field as part of your PXSelector attribute:
[PXSelector(typeof(Search<SomeTable.someField, Where<SomeTable.someField,Like<Current<MyFilter.myFieldWildcard>>>>))]
I am wondering about how to search in J2ME. I have been searching in the internet, so many result show to me, and I see in Java2s.com I got a result use RecordFilter and matches method for search in record store.
But my problem is, when I need to pass 2 or more parameters into it. How can result matches with these parameter?
And how to sort descending or ascending like bubble sort?
Concatenate your searches into a single String variable. Separate each of them with ; for example. In the code of the matches method explode the String to get each search criteria.
To make the filter in effect create an instance of SearchFilter and call the matches method with the concantenated String as its param.
For the sort implement the RecordComparator interface ; implement the compare method to build your sort criteria. Make a google search about j2me+recordcomparator to see examples about how to make sorts.
EDIT :
In the code of the matches method explode the String param obtained from the byte[] param. Treat each String exploded to make the criteria.
As I understand you want to pass two string as a search criteria when you wrote :
SearchFilter search = new SearchFilter(txtSearch.getString(), strType);
So in the constructor there should be two params !!!
When you want to make the matching then call
if searchFilter.matches((search1+";"+sType).getBytes())
Then explode the candidate param into two String when you code the matches method.
When I save my Data in RMS I save it as a String[] like I want to save Name, Age,Salary,EmpID for each employee I save it create an array and convert it to bytes and save it in RMS. When i retrieve it i do the reverse process. Now if i want to get employee with names starting with A and with salary 10000 i use the following filter
class UtilFilter implements RecordFilter{
public UtilFilter(String str_searchText,String str_searchText1)
{
this.str_searchText = str_searchText.toLowerCase();
this.str_searchText1 = str_searchText1.toLowerCase();
}
public boolean matches(byte[] bt_byteData)
{
String str_str = "";
String str_str1 = "";
//here goes code how u get back ur String[] from RMS say u get it in Data
str_str = Data[0].trim();
str_str1 = gd_cd.Data[2].trim();
if(str_searchText != null && str_searchText1 != null && str_str.equals(str_searchText) && str_str1.equals(str_searchText1 ))
{
return true;
}
else
{
return false;
}
}
}
This way i can filter any no of parameters.Hope tht helps! :)
For now I have field "String firstName" it converted to "first_name" and i want "firstname" as default in Hibernate. Is it posible?
5.5.2.1 Table and Column Names
class Person {
String firstName
static mapping = {
table 'people'
firstName column:'firstname'
}
}
You can change the naming strategy for the entire project. From the documentation https://grails.github.io/grails-doc/latest/guide/GORM.html#customNamingStrategy.
By default Grails uses Hibernate's
ImprovedNamingStrategy to convert
domain class Class and field names to
SQL table and column names by
converting from camel-cased Strings to
ones that use underscores as word
separators. You can customize these on
a per-instance basis in the mapping
closure but if there's a consistent
pattern you can specify a different
NamingStrategy class to use.
Configure the class name to be used in grails-app/conf/DataSource.groovy in the hibernate section, e.g.
So, something like this in your DataSource.groovy
dataSource {
pooled = true
dbCreate = "create-drop"
…
}
hibernate {
cache.use_second_level_cache = true
…
naming_strategy = org.hibernate.cfg.DefaultNamingStrategy
}