Character limitation in text item field in Oracle Apex - sql

I have a TEXT item field - order number, where user can enter his details.
When a user enters order number starting with 1, the character limit should be restricted to 14.
When a user enters order number starting with 2, the character limit should be restricted to 11.
How can we do it in Oracle Apex?

Click Create Dynamic Action, set following properties:
Event - Key press
Selection Type - Item
Item(s) - name of your item
Condition - Javascript expression with following expression (where P_ITEM is name of your item):
($v('P_ITEM').length >= 14 && $v('P_ITEM').substring(0,1) == '1') ||
($v('P_ITEM').length >= 11 && $v('P_ITEM').substring(0,1) == '2')
Action - Cancel Event
P. S. I have not tried to copy and paste long values. Probably, you need some additional javascript code for that. Also, this code can't restrict values starting from other symbols.
P. P. S. Also it is possible to do with Validations (it is quite simple, but validations are processed on the server side) and in triggers (both solution use PL/SQL code).

Related

Odoo force a field higher than x

In sales order, there is a field discount %. Is it possible to ensure the users only input value lower than x and it will not accept any value higher than x.
You can achieve this with creating a function using #api.onchange('discount') decorator on python code to ensure discount value is not higher than x, if higher then set x to discount field and also possible to show warning popup from that function.
But if python code change is not prefered, you can also achieve this with Automated action where you create a new rule on sale.order.line, set trigger On form modification, action Execute python code and add the following code
if record.discount > 10:
record.discount = 10
Where 10 is the value of x. This will ensure discount is always less than x.
Op1: If you want to ensure that behaviour you can add an sql constraint to the database, this will work fine if your X value never change, something like this:
_sql_constraints = [
('discount_less_than_X', 'CHECK(discount < X)', 'The discount value should be less than X'),
]
This constraint will trigger in all cases(create, write, import, SQL insert).
Replace X with the value desired.
Op2: Use decorator api.constrains, get X value from somewherelse and apply the restriccion, something like this:
#api.constrains('discount')
def _check_discount(self):
# Create a key:value parameter in `ir.config_parameter` table before.
disscount_max_value = self.env['ir.config_parameter'].sudo().get_param('disscount_max_value')
for rec in self:
if rec.disscount > int(disscount_max_value):
raise ValidationError('The discount value should be less than {}'.format(disscount_max_value))
I hope this answer can be helful for you.

WooCommerce: How to automatically select variation attribute dropdown field when there is only 1 option?

So I feel like this isn't too complicated of a request, but I simply can't figure it out. On my WooCommerce site, I have some variable products. There are 3 dropdown variation attributes in the following order (top to bottom): Color, Type, and Part Number. Each variation has a unique part number (only 1 part number per combination), so there is literally no need for the user to select the part number after they have chosen color & type. However, I need that part number to display for purposes of my product feed and so the customer can see the part number they have chosen by the previous 2 options.
My question is; since selecting a "Color" and "Type" narrows the final field ("Part number") down to only 1 option, how do I instruct WooCommerce to automatically select the single "part number" option that's available?
You can do this with JS:
jQuery('a.toggle_component').click(function(e){
if(!(jQuery(e.target).parents('.component').find('select.component_options_select > option[selected=selected]').val())) {
jQuery(e.target).parents('.component').find('select.component_options_select > option:nth-child(2)').attr('selected','selected');
jQuery(e.target).parents('.component').find('select.component_options_select').change();
}
});

Multiple change of lotus type groups

maybe someone once wrote a script for mass change of lotus type groups? Mass but not all, only grups with first two characters begins on ('GD') i need change mostly type from mail only (3) to Multipurpose (0).
Just select the groups, create an agent with this code, that runs on selected documents:
FIELD GroupType := "0";
If you really want to do the selection in your agent, then let it run on "all documents in view" and add a selection before the action:
SELECT #Begins( ListName ; "GD" );
FIELD GroupType := "0";
As this will run a lot slower I would manually select the groups and use the first agent as selecting is as easy as setting the cursor to the first group with "GD", then scroll down to the last one and click it while holding the Shift- Key.

Having Issue on Field Calculator With Python in ArcMap

I have tried all of below snippets to use Python Parser in Field Calculator and update the values of a field called type based on a filed called MamerMN but in all of them I am getting Syntax error in Geoprocessing result window!
if !MamerMN! <= 0.151560:
return 1
and
if (!MamerMN! <= 0.151560):
return 1
and
if (MamerMN <= 0.151560):
return 1
and
def(MamerMN)
if MamerMN <= 0.151560:
return 1
and
def(MamerMN)
if (MamerMN <= 0.151560):
return 1
Can you please let me know what I am doing wrong?
You are writing your functions wrong. In the Field Calculator, make sure you check 'Show Codeblock' so the Pre-Logic Script Code box appears. Inside the Pre-Logic box, write your function-
def calcValue(mamerMN):
if mamerMN <= 0.151560:
return 1
and then in the box under, where it says the field_name =
you should write the name of the function and the field value you are passing to it surrounded by exclamations. So if your function above is named calcValue you would write
calcValue(!mamerMN!)
Without seeing a graphic of what your Field Calculator looks like, I suspect #csterling is probably right. However, an alternative is to just Select by Attribute where "mamerMN" <= 0.151560, then Field Calculate your selected features to 1 the regular way without necessitating a codeblock.

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –
First Name (First_Name)
Last Name (Last_Name)
Year (Year)
Number (Number)
I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.
Heres is my script:
void onetime.UpdateInv()
{
for each Inventory_Record in Management
{
FN = Inventory_Record.First_Name.subString(0,1);
LN = Inventory_Record.Last_Name.subString(0,1);
YR = Inventory_Record.Year.subString(2,4);
NO = Inventory_Record.Number;
outputstr = FN + LN + YR + NO;
Inventory_Record.Inv_Num1 = outputstr;
}
}
I get this error back when I try to run this function
Error.
Error in executing UpdateInv workflow.
Error in executing For Each Record task.
Error in executing Set Variable task. Unable to update template variable FN.
Error evaluating STRING expression :
Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.
this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.
you just have put a null check on each field and u r good to go.
you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )
the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.
Since you are using substring directly in year Field, I am assuming the
year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);
so here's the formula
if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number
Let me know ur response if u implement this.
Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:
The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.
All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.