How do you do TSQL CHARINDEX or TSQL IN in BQL? - acumatica

I am trying to determine if the first two characters of a field value match one of a finite list of values ie ("RG", "HC", "LP", etc) maybe 5-10 of these values. I dont care which one it is, just that it is "valid".
In SQL i could do it with CHARINDEX, or IN - how can i do this with BQL?
I could probably do a SWITCH/CASE but it seems inefficient to spell them all out like that.
Specifically, I am trying to do this in a DBCalced attribute for a field:
[PXDBCalced(typeof(Switch<Case<Where<Substring<INItemLotSerial.lotSerialNbr,int1, int2>, In<EDType>>, Substring<INItemLotSerial.lotSerialNbr,int1, int2>>, StringEmpty>), typeof(string))]
The In above doesnt seem to do what i expected - not sure what it is intended for or how to use IN<> as i found no doc. I defined EDType as a constant string with all my values split by commas.
Thanks

Instead of doing it through pure BQL statements, my recommendation would be to handle the FieldUpdated event. You can do it from the graph, or you can create a custom attribute that you will apply to your field. There's a few different ways that you can create this custom attribute, but the simplest definition would look something like that:
private sealed class MyCustomBehaviourAttribute : PXEventSubscriberAttribute, IPXFieldUpdatedSubscriber
{
public void FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
// Add your logic here
}
}
You may also search inside the source code (using the find in files function on screen SM.20.45.70) and search for attributes which implement IPXFieldUpdatedSubscriber, or that call FieldUpdated.AddHandler to subscribe to the event manually.

I couldnt fit this into a comment but i used this attribute:
[PXDBCalced(typeof(Switch<Case<Where<Substring<INItemLotSerial.lotSerialNbr, int1, int2>, Equal<EDRG>,
Or<Substring<INItemLotSerial.lotSerialNbr, int1, int2>, Equal<EDAP>,
Or<Substring<INItemLotSerial.lotSerialNbr, int1, int2>, Equal<EDHC>,
Or<Substring<INItemLotSerial.lotSerialNbr, int1, int2>, Equal<EDRN>,
Or<Substring<INItemLotSerial.lotSerialNbr, int1, int2>, Equal<EDPP>,
Or<Substring<INItemLotSerial.lotSerialNbr, int1, int2>, Equal<EDPT>
>>>>>
>, Substring<INItemLotSerial.lotSerialNbr, int1, int2>>, StringEmpty>), typeof(string))]
Where the EDRG, etc are constants.
Like i said, not the prettiest, but seems effective.

In<T> is not supposed to be used with anything but parameters (e.g. Required<T> or Optional<T>) because it is accepting a vector or values as its second operand, that can be achieved now only passing an array to match a parameter.

Related

Can´t find the correct class for string methods in Godot

I am trying to make my program read and edit text. I was trying to use the Position=find ( String , 0 ) method but I get the error:
The method "find" isn't declared in the current class.
I have tried different classes but I cant find the correct one.
Which would that be?
How may I find the correct class in the future?
Thanks in advance.
The find is in the String class.
From the documentation:
int find ( String what, int from=0 )
Finds the first occurrence of a substring. Returns the starting position of the substring or -1 if not found.
So what happens?
When you do Position = find(String, 0) You are calling find from which ever class your code is inside, not from String.
Furthermore, I only see one String there… Which String do you want to find in which one? You need two. Yes, find only takes one String, but it is an instance method, not a static method. You are meant to call it on the one you want to search, like this:
var position := string_in_which_you_are_looking.find(string_you_are_looking_for, 0)

Kotlin method chaining to process strings in a list

I have a list of strings I get as a result of splitting a string. I need to remove the surrounding quotes from the strings in the list. Using method chaining how can I achieve this? I tried the below, but doesn't work.Says type interference failed.
val splitCountries: List<String> = countries.split(",").forEach{it -> it.removeSurrounding("\"")}
forEach doesn't return the value you generate in it, it's really just a replacement for a for loop that performs the given action. What you need here is map:
val splitCountries: List<String> = countries.split(",").map { it.removeSurrounding("\"") }
Also, a single parameter in a lambda is implicitly named it, you only have to name it explicitly if you wish to change that.

GraphQL Schema Definition Error

I am trying to define GraphQL schema like this:
type Obj {
id: Int
0_100: Int
}
But it gives following exception.
'GraphQLError: Syntax Error: Expected Name, found Int "0"',
How can I define attribute starting with numeric, -, + signs.
This is the regexp for names in GraphQL: /[_A-Za-z][_0-9A-Za-z]*/. Anything that does not match is not allowed.
Sample URL:
http://facebook.github.io/graphql/June2018/#sec-Names
Numerical parameter names do not work in GraphQL.
You can probably prefix it with a string like _0_100, but it's fairly unusual and I'd recommend against it. Consider using words to name your parameters instead.

writing an excel formula with multiple options for a single parameter

I would like to access information from a HTTP based API and manipulate it with excel.
The API returns about 20 pieces of information, and you can get that information by looking up any number of about ten lookup fields: name, serial number etc.
I want to write a function similar to the Match Function in excel where one of the parameters (in this case MATCH TYPE) has multiple possible values.
I have a list of values (the 20 pieces of information the API can return) and I want to make these pieces of information the possible return values for one of the Functions parameters.
How do I do I create a function where one parameter has a list of possible values?
And how do I add tooltip help statements to those parameter options so people know what they are?
You want to use an Enum.
In the declarations part of your module (before any subs or functions) you can place code like this.
Enum MyFunctionsArgValue
LessThan
Equal
GreaterThan
End Enum
This will assign each of these keywords an integer value, starting at zero and counting up. So LessThan = 0, Equal = 1, and GreaterThan = 2. (You can actually start at any number you want, but the default is usually fine.)
Now you can use it in your function something like this.
Function MySuperCoolFunction(matchType as MyFunctionsArgValue)
Select Case matchType
Case LessThan
' do something
Case Equal
' do it different
Case GreaterThan
' do the opposite of LessThan
End Select
End Function
To get the tool tip, you need to use something called an Attribute. In order to add it to your code, you'll need to export the *.bas (or *.cls) file and open it in a regular text editor. Once you've added it, you'll need to import it back in. These properties are invisible from inside of the VBA IDE. Documentation is sketchy (read "nonexistent"), so I'm not sure this works for an Enum, but I know it works for functions and module scoped variables.
Function/Sub
Function MySuperCoolFunction(matchType as MyFunctionsArgValue)
Attribute MySuperCoolFunction.VB_Description = "tool tip text"
Module Scoped Var
Public someVar As String
Attribute someVar.VB_VarDescription = "tooltip text"
So, you could try this to see if it works.
Enum MyFunctionsArgValue
Attribute MyFunctionsArgValue.VB_VarDescription = "tool tip text"
LessThan
Equal
GreaterThan
End Enum
Resources
https://www.networkautomation.com/automate/urc/resources/help/definitions/Sbe6_000Attribute_DefinintionStatement.htm
http://www.cpearson.com/excel/CodeAttributes.aspx

how can i assign indented block in vim a special syntax highlighter?

for convenience in grouping couchdb functions
i created a file format that groups separate things together using yaml
it basically contains entries in the form of name.ext: |
followed by a intended block of code in the language fitting to .ext
for more pleasant editing i'd like to have vim use the correct syntax highlighters for them
edit
some code examples as requested
simple:
map.coffee: |
(doc) ->
for item in doc.items:
emit [doc.category, item], null
return
reduce: _count
more complex:
map.coffee: |
(doc) ->
emit doc.category, {items: 1, val: doc.value}
return
reduce.coffee: |
(keys, values, rereduce) ->
ret = {items: 0, val: 0}
for v in values
ret.items += doc.items
ret.val += doc.val
return ret
I believe that what you want it to make use of Vim's syntax regions (:help syn-region). But regions take delimiters as parameters.
You have a well defined start but not a defined end, maybe you could work your way around by establishing some conventions here like "2 empty new lines at the end".
There are similar answers that might give you a hint (including the docs) on how to implement a solution, like: Embedded syntax highligting in Vim
Also interesting and similar approach is this Vimtip: http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file
You have to write your own syntax file, and define a syntax region for each of your entries. Inside that region, you can then syntax-include the corresponding language as defined by your ext. Read all the details at :help :syn-include.
If that sounds too complicated, check out my SyntaxRange plugin. It is based on the Vimtip mentioned by alfredodeza. With it, you can quickly assign a syntax to a range of lines, e.g. :11,42SyntaxInclude perl

Resources