How do you set a vid field with block item value in rebol/red? - rebol

That works:
test: "test"
view [field test]
That doesn't:
test: ["test1" "test2"]
view [field test/1]

In Red, paths are not directly accepted by VID, but they can be provided after some keywords like data, which can be used in your case to indicate the value of the field widget:
view [field data test/1]
An alternative way is to build the VID block dynamically, the simplest way here would be to use compose:
view compose [field (test/1)]

Related

How to update a Podio category using PHP API

I'm using a webhook to kick off a series of PHP scripts that take advantage of the Podio PHP API. I've tried using several different API calls but haven't been able to sort this out. This is a test file I'm using so the actual logic of what its doing doesn't make much sense. When I run the code below I get the error.
PHP Fatal error: Uncaught PodioBadRequestError: "Invalid value "status" (string): Not a valid option"
Request URL: http://api.podio.com/item/<removed>/value/<removed>
Stack Trace:
/data/www/default/contracts/lib/podio-php-master/lib/Podio.php(357):
Podio::request('PUT', '/item/<removed>...', Array)
/data/www/default/contracts/lib/podio-php-master/models/PodioItemField.php(55): Podio::put('/item/<removed>...', Array)
/data/www/default/contracts/test-category.php(25):
PodioItemField::update(<removed>, <removed>, Array, Array)
{main}
thrown in /data/www/default/contracts/lib/podio-php-master/lib/Podio.php on line 291`
Here is my code:
//dummy item_id
$item_id = 123456789;
//dummy field_id
$field_id = 987654321;
//Get the category field value
$item = PodioItem::get_field_value($item_id, $field_id);
//Create a variable with the text of the selected category option for validation
$button_value = $item[0]['value']['text'];
//Print the text of the selected option
print $button_value;
//Now that I have validated the current selection I want to change it
//These are the names of the attributes for my category
$my_attributes = array("status", "text", "id", "color");
//These are the values I want to update them to
$my_options = array("active","Generated",21,"DCEBD8");
//This should update the record in podio with the new values
PodioItemField::update($item_id, $field_id, $my_attributes, $my_options);
I reviewed all of the examples in the documentation but I feel like I'm missing something simple. Is anyone familiar with this that can tell me what I'm doing wrong? I've tried to comment the code to make it clear what I expect to be happing on each line but I can definitely clarify more if needed.
You are passing the attributes in the wrong method. To update the Category field you just pass the id of the option that you want to change in an array. So the $my_attributes array must be like,
$my_attributes = array(21);//id of the category option
And the $my_options array should like this,
$my_options = array('silent' => true, 'hook' => false);
This should update the item in Podio with the new values,
PodioItemField::update($item_id, $field_id, $my_attributes, $my_options);

How to map two variables from SQL Query - MyBatis

So, I have this select query below, which joins two tables and retrieves a String:
<select id =“getAppVerByConfId” parameterType=“java.lang.String” resultType=“java.lang.String”>
SELECT t.app_ver
FROM
application a
JOIN transaction t on t.txn_id = a.txn_id
WHERE
a.confirmation_id = #{0}
</select>
and then I used that as a template to write a 2nd query, which is nearly identical, but just retrieves a different parameter from the table.
<select id =“getStepNameByConfId” parameterType=“java.lang.String” resultType=“java.lang.String”>
SELECT t.step_name
FROM
application a
JOIN transaction t on t.txn_id = a.txn_id
WHERE
a.confirmation_id = #{0}
Both of these work fine on their own, and they're used at the same point in the program. But there's got to be a better way than this surely? I should be able to make the query once, and then map the results to what I want, correct? Should I make a resultset, and then be able to pull them out? Maybe as a HashMap and I can retrieve the values by keys? Is this a situation where I can USE the AS operator? i.e. "SELECT t.app_ver AS appVersion"? My thinking is that's for passing variables into the query, though, and not for getting them out?
If there's any thoughts on this I would love to hear them. I'm basically trying to combine these into one query, and I need to be able to retrieve the right value and not assign app_ver to step_name or vice versa.
Cheers
As you say it's not a bad idea use alias (t.app_ver as appVersion) in your select but it is just the name of the column which will be mapped. So in the case you use alias as next t.app_ver as appVersion, t.step_name as stepName your column names will be appVersion and stepName.
Then, to map your result you have multiple choices the idea to map it in a map structure is not a bad idea and it's easy, you just need to put your result type as hashmap, it will be something like that (and it's not need any Resultmap):
Hashmap
(Example in offical page)
<select id="selectPerson" parameterType="int" resultType="hashmap">
SELECT * FROM PERSON WHERE ID = #{id}
</select>
The column will be the key and the row values the value in the map.
keyed by column names mapped to row values
So to get your values you will need to use the column name as key in the map:
String appVersionValue = map.get("appVersion");
Resultmap
Other way it to create a class with the properties you need to map and then create your resultmap.
A resultmap is defined as next:
resultMap – The most complicated and powerful element that describes
how to load your objects from the database result sets.
Your class would be like:
public class Application{
private String appVersion;
private String stepName;
//.... getters and setters
}
And your result map would map the column name with the class properties specifying the type with the class created for this (In this case is Application):
<resultMap id="applicationResultMap" type="Application">
<result property="appVersion" column="appVersion"/>
<result property="stepName" column="stepName"/>
</resultMap>
(Be careful, because in this example the columns and properties are called equal, there are cases where the column is called app_version and the property appVersion for example so there would be <result property="appVersion" column="app_version"/>
Finally in your select you specify to use this resultmap:
<select id="selectMethodName" resultMap="applicationResultMap">
select t.app_ver as appVersion, t.step_name as stepName
from your_table
</select>

Selecting dropdown values using Select class?

I have two doubts:
Suppose if in a drop down there are two values with the same name, then how can I select the one value from them using Select class?
Suppose in a drop down there is a value "Emergency". I need to run the script in dev and production. In dev url the drop down value is coming in Uppercase i.e EMERGENCY. But in Prod env the drop down value is coming in lowerase i.e Emergency.I need to make the script in such a way that it will select the dropdown value irrespective of the case of the drop down value. I can do it by checking if the env is dev then do this else do this. but i dont want to do like this way. How can i do it using Select class or any other relevant way to do it?
Doubt 1: Suppose if in a drop down there are two values with the same name,
then how can I select the one value from them using Select class?
You can go for selectByIndex or selectByValue method. So If you know that out of the two options in the drop-down which are same, and you want to select the 2nd one then select the option by index.
Select select = new Select(driver.findElement(By.id("dropDown_id_here")));
select.selectByIndex(2);
If the text of the 2 options is same and the values are different, then you can use:
select.selectByValue("op2");
Doubt 2: Suppose in a drop down there is a value "Emergency". I need to run the
script in dev and production. In dev url the drop down value is coming
in Uppercase i.e EMERGENCY. But in Prod env the drop down value is
coming in lowerase i.e Emergency.I need to make the script in such a
way that it will select the dropdown value irrespective of the case of
the drop down value. I can do it by checking if the env is dev then do
this else do this. but i dont want to do like this way. How can i do
it using Select class or any other relevant way to do it?
Select select = new Select(driver.findElement(By.id("dropDown_id_here")));
List<WebElement> options = select.getOptions();
for(WebElement option : options)
{
if(option.getText().equalsIgnoreCase("emergency"))
{
option.click();
break;
}
}
Please note that I have written the above code on the fly in this editor. It could be syntactically wrong. Kindly just get the idea out of it.
you have other options
select by value
selectByValue(value);
Select by index
selectByIndex(index);

Update Product Name, Description, Short Description in Magento

The solution for this was almost provided in this answer https://stackoverflow.com/a/14249171
It does indeed replace the product name properly.
But I needed to take it a step further and check the productname, description and short description to replace 'example' with 'test' in all three areas. I wasn't sure if it was possible to modify the current script provided to include these other attributes.
this do the trick :
$newName = str_replace('example','test',$product->getName());
$product->setName($newName);
Find it and add the other attributes :
$newDescription = str_replace('example','test',$product->getDescription());
$product->setDescription($newDescription);
$newShortDescription = str_replace('example','test',$product->getShortDescription());
$product->setShortDescription($newShortDescription);
Then save each attribute like this :
$product->getResource()->saveAttribute($product,'description');
$product->getResource()->saveAttribute($product,'short_description');
Or just save the product (time and resource consuming)
$product->save();
To select only product having example in name OR description OR short_desc use this
-addAttributeToFilter(array(array('attribute'=>'name','like'=>'%example%'), array('attribute'=>'description','like'=>'%example%'),array('attribute'=>'short_description','like'=>'%example%')))
Instead of
->addAttributeToFilter('name',array('like','%example%'))

How do I get my data to show up in my ALV?

I'm thinking that I'm probably missing an export parameter (from my Function Call POV).
In the REUSE_ALV_GRID_DISPLAY function call, the parameters I pass around are:
Exporting:
i_callback_program,
i_callback_pf_status_set,
i_callback_user_command,
is_layout,
it_fieldcat,
i_save
Tables:
t_outtab
And the exceptions plus handling.
I've checked that the internal table that I pass has data and it does.
I think the information I put up will suffice but if you really need to see the code, I'll do so.
I'm a noob and any help would be appreciated.
Thanx.
There are several ways to use ALV, so we may indeed need more info on your code to help.
First Method is to use the function module REUSE_ALV_GRID_DISPLAY. This will directly display the table content in the output dynpro. If all you need is a display, then go for it, as this is the simpliest : If the table structure is in the dictionnary, this call can be as simple as the following (this will display all members of the struct as column)
myreport = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = myreport
it_excluding = exclude_tab
TABLES
t_outtab = display_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
If the structure is declared in the program, then you have to create a field catalog.
the following code can serve as basis :
FORM fill_fieldcat CHANGING p_fieldcat TYPE slis_t_fieldcat_alv.
* Data definition
DATA ls_fieldcat TYPE slis_fieldcat_alv.
* Macro definition
DEFINE append_fieldcat.
clear ls_fieldcat.
ls_fieldcat-fieldname = &1. * name of the field in struct
ls_fieldcat-tabname = &2. * name of the table
ls_fieldcat-row_pos = &3. * column
ls_fieldcat-ref_fieldname = &4. * field in ref table
ls_fieldcat-ref_tabname = &5. * ref table
ls_fieldcat-outputlen = &6. * size of output
ls_fieldcat-seltext_m = &7. * text (space if using the element typetext)
ls_fieldcat-ddictxt = 'M'.
ls_fieldcat-key = &8. * is this a key field in table
ls_fieldcat-emphasize = &9. * emphisze column display
append ls_fieldcat to p_fieldcat.
END-OF-DEFINITION.
* Init.
REFRESH p_fieldcat.
* Append fielcatalog for ALV
append_fieldcat:
'FORMATIONCODE' 'DISPLAY_TAB' 1 'SHORT' 'HRP1000' 12 'Code Stage' space space,
'FORMATIONTEXT' 'DISPLAY_TAB' 1 'STEXT' 'HRP1000' 20 'Libelle Stage' space space,
'SESSIONID' 'DISPLAY_TAB' 1 'OBJID' 'HRP1000' space 'Session' space space,
'BEGDA' 'DISPLAY_TAB' 1 'BEGDA' 'HRP1000' space 'Debut' space space,
'ENDDA' 'DISPLAY_TAB' 1 'BEGDA' 'HRP1000' space 'Fin' space space,
ENDFORM. "fill_fieldCat
you then call the form to create the field catalog, and use it in the it_fieldcat parameter of the function call.
Second method is to use ABAP-Object. Use check se83 for exemples of this use. the basis is as follows :
In your Dynpro you declare a custom container with a given name ("ALV_CONT"). Then in then PBO of the dynpro you initialize the container and put an ALV objct inside :
* global variables :
DATA : delegationlist_table TYPE REF TO cl_gui_alv_grid,
delegationlist_container TYPE REF TO cl_gui_custom_container.
data : gs_layout TYPE lvc_s_layo.
in PBO
IF delegationlist_container IS INITIAL.
* create a custom container control for our ALV Control
CREATE OBJECT delegationlist_container
EXPORTING
container_name = 'ALV_CONT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
* create an instance of alv control
CREATE OBJECT delegationlist_table
EXPORTING
i_parent = delegationlist_container.
* Set a titlebar for the grid control
gs_layout-grid_title = 'Délégations'.
gs_layout-sel_mode = 'A'.
gs_layout-cwidth_opt ='X'.
* set table as data source
* the struct name *must* be uppercase
* the table must have this struc
CALL METHOD delegationlist_table->set_table_for_first_display
EXPORTING
i_structure_name = 'ZPRT_DELEGATIONLIST'
is_layout = gs_layout
CHANGING
it_outtab = delegationlist.
ENDIF.
Hopes this help,
Regards
Guillaume PATRY
EDIT: Oh, and another thing - if you're really in POV (process on Value-Request = F4), be aware that there are limitations to what you can do. Try your code in a simple report right after START-OF-SELECTION, and if that works, try the same code in a POV module.
===
If you don't pass a structure name, you have to ensure that you pass a complete (!) field catalog, otherwise the ALV grid might start to work erratically or not at all. Use the function modules LVC_FIELDCATALOG_MERGE and LVC_FIELDCAT_COMPLETE (in this order) to get a LVC field catalog that can be used with the classes or REUSE_ALV_GRID_DISPLAY_LVC.
A couple people here suggested using the REUSE_ALV_GRID_DISPLAY. I'm sure this is a common way to get things done (I used to use it myself), but I've taken a sap delta course recently and they strongly suggested to not use it anymore (you can look it up, REUSE_ALV_GRID_DISPLAY is not officialy supported by SAP anymore).
Instead, use CL_SALV_TABLE, documentation here: http://help.sap.com/erp2005_ehp_04/helpdata/EN/d7/b22041aa7df323e10000000a155106/frameset.htm
It's actually rather convenient to use too.
Thanks for the effort but as it turned out, the mistake I did was that I didn't capitalize field names in building the Field Catalog. Such a newbie mistake. I guess I won't be doing that mistake again any time soon.
-migs
Pass the output internal table to the FM Parameter "t_outtab".
It will print your data output.