I'm trying to load some tables using the script, in order to create new tables according to an IF condition.
My script is the following:
LOAD Pippo
if(color = 'green', 'ok',
if(color = 'yellow' and text <> 'No control needed', 'check',
if(color = 'red' and text <> 'Control now', 'check', 'ok'))) as Pippo1
In the line with the color = yellow, I want to catch different cases because there are many text occurrences starting with 'No control needed' (for example No control needed (for 1 week), No control needed (for 2 weeks)), and I want to select them all.
I tried using: text<>'No control needed'*, but it did not work.
Any suggestions?
Index() function can be used in this case.
Index() will search for string-in-a-string and if not found will return 0 else will return the position on which the searched string is found.
In your case this can be expressed as:
Index(text, 'No control needed') = 0
and the full expression:
LOAD
Pippo,
if(color = 'green', 'ok',
if(color = 'yellow' and Index(text, 'No control needed') = 0, 'check',
if(color = 'red' and text <> 'Control now', 'check', 'ok'))) as Pippo1
Related
This searches my WPDataTable and filters it to only display rows containing 'apple':
function filterGlobalSearch( $tableDescriptionObj, $tableId , $wpDataTablesObj) {
if( $tableId == 1 ){
$tableDescriptionObj->dataTableParams->oSearch = array(
'bSmart' => false,
'bRegex' => false,
'sSearch' => 'apple'
);
}
return $tableDescriptionObj;
}
add_filter('wpdatatables_filter_table_description','filterGlobalSearch', 10, 3);
Please can you tell me how to search for 'apple' OR 'banana'? (to show rows that contain either word).
I've found similar answers on StackExchange and other forums about multiple OR strings (for example here) but can't seem to get them working.
Have already tried:
'apple|banana'
'apple||banana'
'apple'|'banana'
'apple'||'banana'
'apple' OR 'banana'
array('apple', 'banana')
Grateful for any assistance.
I've been provided a working solution that I'll share here:
'bRegex' => false should be changed to true.
'apple|banana' is the search string.
I am populating Gravityforms fields using the functions.php from my template and it works like a charm, but I have one field that is ... a challenge. I have been able to populate the choices from my database just fine, but with the functions.php I cannot control the content of the display area of the field so that I can, for example, add a title or header for each category. Is there a way to programattically adjust the display here's an example of what im hoping to accomplish
RadioButton Choice (Field ID 21)
Dark Colors (category title)
maroon (choice 1)
navy blue (choice 2)
black (Choice 3)
Standard Colors (Category Title)
Red (choice 4)
blue (choice 5)
gray (Choice 6)
Light Colors )Category Title)
pink (choice 7)
sky blue (choice 8)
white (Choice 9)
I am just looking for a way to add the category title between the choices. My DB Query has the categories as part of the response, but the only option I have to populate choices to to feed an array.
I have seen where I can add additional Gravityform fields and have them controlled by the same "single select" radio button option, but the categories involved change based on the DB query I call to dynamically populate the choices and could range from 1 category to 10, which will not have correlating fields in the form itself, as this is all under a single radio-button field.
Any thoughts would be appreciated.
I was able to use the link I posted in my comment to provide a solution. As part of my "choices"
here is the function for the Pre-Render to populate choices. In this case I am populating a radio-button field with product images instead of default radio buttons
add_filter('gform_pre_render_1', 'populate_choices');
function populate_choices($form) {
global $wpdb;
// Now to get a list of the products I want to include on this radio-button
$dataQ = "
SELECT category, product_id, product_name
FROM product_table
WHERE product_type = 'whatever I am looking for'
ORDER BY category, product_name ASC
";
$dataR = $wpdb->get_results($dataQ);
$dataList = array();
// get current protocol to use in Product Images
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// Rebuild URL for use with product image graphics
$productImageUrl = $protocol.$_SERVER['HTTP_HOST'].'/wp-content/product_images/';
// Generate list of choices for the radio-button, along with category headers
foreach ($form['fields'] as $field) {
if ($field->id == '32') { // 32 My specific radio-button field
$category = "";
foreach ($dataR as $data) {
if ($category != $data->category) {
// If I hit a new category, add the "header" item to the "choices" list with a unique search item to identify it, in this case "###"
$category = $data->category;
$dataList[] = array(
'text' => '#'.$category."#",
'value' => ''
);
}
$productImage = str_replace(" ","",strtolower($data->product_name)).".jpg";
$productID = $data->product_id;
$dataList[] = array(
'text' => $data->product_name,
'value' => $productID,
'isSelected' => false,
'price' => '0.00',
'imageChoices_image' => $productImagehUrl.$productImage
);
}
$field->choices = $dataList;
}
}
}
I then added a specific field modifier to update the "#category#" choice elements with html to make the category names show up.
// numbers after filter = "1" for form ID 1, "32" for field ID 32
add_filter('gform_field_choice_markup_pre_render_1_32', function( $choice_markup, $choice) {
if ( strpos( $choice['text'], '#' ) === 0 ) {
$categoryName = str_replace("#","",$choice['text']);
$choice_markup = '
<li style="width:100%;text-align:left;">
<span style="color:#000000;font-weight:bold;font-size:18px;">
<br>
'.$categoryName.'
</span>
</li>
';
}
return $choice_markup;
}, 10, 2);
I have been working for my below code for few days, but still can't get it work. What I intended to do is when one select raw-material product type (customized field) in Product Create section, Buy route will be selected. On the other hand, select "Finish Good", Manufacture and MTO route will be selected. The below codes does the half because it doesn't clear the previous selected value when switch from Raw-Material to Finish Good. The previous filled up value still remain. Please help! Thx so much.
# api.onchange ('custom_product_type')
def _onchange_custom_product_type (self):
if self.custom_product_type:
self.warehouse = self.env.ref ('stock.warehouse0')
route_manufacture = self.env.ref ('stock.warehouse0'). manufacture_pull_id.route_id.id
route_mto = self.env.ref ('stock.warehouse0'). mto_pull_id.route_id.id
buy_route = self.env.ref ('stock.warehouse0'). buy_pull_id.route_id.id
if self.custom_product_type == 'RM':
self.sale_ok = False
self.purchase_ok = True
self.update ({'route_ids': [(6, 0, [buy_route])]})
elif self.custom_product_type == 'FG' or self.custom_product_type == 'HG':
self.sale_ok = True
self.purchase_ok = False
self.update ({'route_ids': [(6, 0, [route_manufacture, route_mto])]})
Your code should work, but you can try to remove them with (5, ) before adding the new routes:
self.update({'route_ids': [(5, ), (6, 0, [route_manufacture, route_mto])]})
Actually, I found out my original works after save. Althought previous selected value doesn't change in the "form", it does change after press "Save".
I have this report, every column is generated by the APEX_ITEM package.
APEX_ITEM.CHECKBOX2, APEX_ITEM.DATE_POPUP2
When the checkbox is checked, I would like to enable the DATE_POPUP2 of that row. And disabled it when the checkbox is unchecked.
Is there any way to do this?
Report query:
SELECT APEX_ITEM.CHECKBOX2(1,a.USR_CODIGO,DECODE(NVL((SELECT 1
FROM PROYECTOS_ROLES_USUARIOS pru
WHERE pru.USR_CODIGO = a.USR_CODIGO
AND pru.PRY_ID = :P92_PRY_ID),0),0,'UNCHECKED',1,'CHECKED')) as Incluir,
a.USR_CODIGO as Usuario, APEX_ITEM.SELECT_LIST_FROM_QUERY(2, NVL((SELECT pru.ROL_CODIGO
FROM PROYECTOS_ROLES_USUARIOS pru
WHERE pru.USR_CODIGO = a.USR_CODIGO
AND pru.PRY_ID = :P92_PRY_ID),null), 'SELECT r.ROL_DESCRIPCION, r.ROL_CODIGO
FROM ROLES r WHERE EXISTS (SELECT 1 FROM ROLES_USUARIOS ru
WHERE ru.ROL_CODIGO = r.ROL_CODIGO
AND ru.USR_CODIGO = ''' || a.USR_CODIGO || ''') and r.ROL_CODIGO not in(''MNI_RRHH'',''CAJ_COMPRAS'',''CAJ_VENTAS'',''CTA_CTE_CLIENTES''
,''CTA_CTE_PROVEEDORES'',''TCM_ALQUILERES'',''TCM_COMPRAS'') order by 1', null, 'YES', '%NULL%', '--') as Rol,
NVL((SELECT APEX_ITEM.DATE_POPUP2(3, prus.PRU_FECHA_INICIO, 'dd/mm/yyyy')
from PROYECTOS_ROLES_USUARIOS prus where prus.PRY_ID = :P92_PRY_ID and prus.USR_CODIGO = a.USR_CODIGO),
APEX_ITEM.DATE_POPUP2(3, TO_CHAR(SYSDATE, 'dd/mm/yyyy'), 'dd/mm/yyyy')) as Fecha_Inicio FROM USUARIOS a WHERE a.USR_FECHA_BAJA IS NULL AND exists (SELECT 1
FROM WWV_FLOW_FND_USER
WHERE USER_NAME = a.USR_CODIGO) order by 1;
As Tom suggests in his comment, there are various ways to do this using JavaScript. You could just apply CSS classes to your checkbox and date item and then use some jQuery to perform the action.
Defining this event binding in your page preferences in the 'Execute when page loads' section would do it.
$('input.myCheckBox').click(function() {
var enabled = $(this).prop('checked');
var myDate = $(this).closest('tr').find('input.myDate');
myDate.prop('disabled', !enabled);
if(enabled) {
myDate.next('img').show();
} else {
myDate.next('img').hide();
}
});
With this approach you do not need to apply IDs to your elements. You could also go down the dynamic action route, perhaps triggering a custom event which is interpreted by the dynamic action?
I want to generate a SQL query like the following using Ruby's Sequel:
SELECT * FROM Objects WHERE (color = "red" AND shape = "triangle") OR
(color = "blue" AND shape = "square") OR
(color = "green" AND shape = "circle")
I want to build this query programmatically from a list of conditions, so that I can do something like this:
conditions = [[[:color, "red"], [:shape, "triangle"]],
[[:color, "blue"], [:shape, "square"]],
[[:color, "green"], [:shape, "circle"]]]
DB[:Users].where(conditions.sql_or)
It doesn't have to follow that exact form, but I want to be able to build the conditions programmatically, so it's not sufficient to be able to construct this query by hand.
Try this:
conditions = [
{:color => "red", :shape => "triangle"},
{:color => "blue", :shape => "square"},
{:color => "green", :shape => "circle"}
]
head, *tail = *conditions
tail.inject(DB[:Users].filter(head)){|mem,obj| mem.or(obj) }
I get:
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"Users\" WHERE (((\"color\" = 'red') AND (\"shape\" = 'triangle')) OR ((\"color\" = 'blue') AND (\"shape\" = 'square')) OR ((\"color\" = 'green') AND (\"shape\" = 'circle')))">
I think this will return an equivalent result, using a different SQL query:
DB[:Objects].where('(color, shape) in ?', conditions.sql_value_list).sql
=> "SELECT * FROM `Objects` WHERE ((color, shape) in (('red', 'triangle'), ('blue', 'square'), ('green', 'circle')))"
sql_value_list is documented in http://sequel.rubyforge.org/rdoc/classes/Array.html
Otherwise use:
objects = DB[:Objects].where(conditions[0])
conditions[1 .. -1].each { |c| objects = objects.or(c) }
Which results in:
SELECT * FROM `Objects` WHERE (((`color` = 'red') AND (`shape` = 'triangle')) OR ((`color` = 'blue') AND (`shape` = 'square')) OR ((`color` = 'green') AND (`shape` = 'circle')))
I was looking at Iain's answer, and it's basically the same as my second one, only more succinct; I like its elegance.