Prevent user from Enter-pressing on MESSAGE type I? - popup

Is there any way to disable the enter key when a MESSAGE TYPE I is displayed? The users are just pressing away the note without reading it.
We want to force them to actually click the green button to confirm the message instead (Yes, I know it's dumb, but I was tasked to implement this so wcyd).
SELECT SINGLE text
FROM ZWM_MATVERMERK
INTO lv_verm
WHERE matnr = <lf_main>-matnr
AND werk = <lf_main>-werks.
IF lv_verm IS NOT INITIAL.
MESSAGE | Note: { lv_verm } | TYPE 'I'.
CLEAR lv_verm.
ENDIF.

You can use the function module POPUP_TO_CONFIRM to create a modal dialog which gives you more control than the standard MESSAGE TYPE 'I'.
Among others, this function module has the parameter default_button which decides which button is the one highlighted when the popup appears and thus will be considered clicked when the user just presses enter.
DATA lv_answer TYPE c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
text_question = 'Are you sure?'
default_button = 2
IMPORTING
answer = lv_answer.
" lv_answer will be '1' for yes, '2' for no and 'A' for canceling the dialog.
If you want to make really really sure that the user read the message, then one option is to use POPUP_TO_GET_ONE_VALUE to make the user confirm that they read the message by reciting something from it.
DATA lv_answer TYPE c.
DATA lv_value TYPE pvarfield.
CALL FUNCTION 'POPUP_TO_GET_ONE_VALUE'
EXPORTING
titel = 'Safety check'
textline1 = |This operation will affect { lv_count } items.|
textline2 = |When you are aware of that, please enter "{ lv_count }" below:|
valuelength = 20
IMPORTING
answer = lv_answer
value1 = lv_value.
IF lv_answer = 'J' and lv_value = lv_count.
"...proceed...
ENDIF.
This will look like this:
By the way: There are a lot more standard function modules starting with POPUP_* which cover a wide variety of common use-cases for modal dialogs. Some of those can be really useful.

Related

QgsField won't accept parameter typeName

I'm trying to create new vector layer with the same fields as contained in original layer.
original_layer_fields_list = original_layer.fields().toList()
new_layer = QgsVectorLayer("Point", "new_layer", "memory")
pr = new_layer.dataProvider()
However, when I try:
for fld in original_layer_fields_list:
type_name = fld.typeName()
pr.addAttributes([QgsField(name = fld.name(), typeName = type_name)])
new_layer.updateFields()
QgsProject.instance().addMapLayer(new_layer)
I get a layer with no fields in attribute table.
If I try something like:
for fld in original_layer_fields_list:
if fld.type() == 2:
pr.addAttributes([QgsField(name = fld.name(), type = QVariant.Int)])
new_layer.updateFields()
QgsProject.instance().addMapLayer(new_layer)
... it works like charm.
Anyway ... I'd rather like the first solution to work in case if one wants to automate the process and not check for every field type and then find an appropriate code. Besides - I really am not able to find any documentation about codes for data types. I managed to find this post https://gis.stackexchange.com/questions/353975/get-only-fields-with-datatype-int-in-pyqgis where in comments Kadir pointed on this sourcecode (https://codebrowser.dev/qt5/qtbase/src/corelib/kernel/qvariant.h.html#QVariant::Type).
I'd really be thankful for any kind of direction.

How to get updated HTML radio button in Workflow Inbox?

Since I'm so new for workflow, now I'm stuck at on how to get updated radio button of HTML table in Workflow inbox when click decision button.
STEP 1: ln HTML table, the user can approve or reject WBS by checked radio
STEP 2: When user click confirm, then the workflow will update status for each WBS that shown in the table.
Question:
On STEP 2 - how can I get the HTML text which updated by user action.
For now I've enhanced SAPEVENTS and using 'SAP_WAPI_READ_CONTAINER' to get HTML container.
However, after check the HTML code, the HTML table is not update to user action.
Here's a minimal program which demonstrates how to get the values of the radio buttons. If the user presses Approve on the first line and Reject on the second line, and presses the button Confirm, the method on_sapevent gets group[1]=approve&group[2]=reject.
(works in something like ABAP 7.40 SP8)
REPORT zdemo.
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS at_selection_screen_output.
METHODS on_sapevent FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata postdata query_table.
PRIVATE SECTION.
DATA o_html TYPE REF TO cl_gui_html_viewer.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD at_selection_screen_output.
DATA: l_url TYPE cndp_url,
l_text TYPE string.
IF o_html IS NOT BOUND.
l_text = '<body><form id="form" method="POST" action="SAPEVENT:submit">'
&& REDUCE string( INIT t = `` FOR I = 1 WHILE i <= 2
NEXT t = t && |<div><fieldset id="group{ i }">|
&& |<input type="radio" value="approve" name="group[{ i }]"> Approve |
&& |<input type="radio" value="reject" name="group[{ i }]"> Reject|
&& |</fieldset></div>| )
&& '<p><button type= "submit">Confirm</button></p>'
&& '</form></body>'.
o_html = NEW #( parent = cl_gui_container=>screen0 ).
SET HANDLER on_sapevent FOR o_html.
o_html->set_registered_events( events = value #( ( eventid = o_html->m_id_sapevent ) ) ).
DATA(lt_text) = cl_bcs_convert=>string_to_soli( l_text ).
o_html->load_data(
EXPORTING type = 'text' subtype = 'html' size = strlen( l_text )
IMPORTING assigned_url = l_url
CHANGING data_table = lt_text ).
o_html->show_url( EXPORTING url = l_url ).
ENDIF.
ENDMETHOD.
METHOD on_sapevent.
CONCATENATE LINES OF postdata INTO data(l_post_data) RESPECTING BLANKS.
MESSAGE l_post_data TYPE 'I'.
ENDMETHOD.
ENDCLASS.
PARAMETERS dummy.
DATA go_app TYPE REF TO lcl_app.
LOAD-OF-PROGRAM.
CREATE OBJECT go_app.
AT SELECTION-SCREEN OUTPUT.
go_app->at_selection_screen_output( ).

Is there a way to store message box settings to be used repetitively in Powershell?

I'd like to use the same message box repetitively in a Powershell script, without having to reiterate all the settings each time. I initially thought that I would store it as a variable:
$StandardMessage = [System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
But as I found out this simply stores the user's response to the message box in the variable.
What I would like to do is something similar to the following pseudo-code:
$StandardMessage = [System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
While(true){
If(condition){
$StandardMessage
}
If(condition2){
$StandardMessage
}
}
Where the conditions would be time-based. This is essentially displaying a message at specified times during the day.
Asked another way (and perhaps more clearly): Is it possible to 'define' a messagebox without actually 'showing' it?
You need to use a Function my good man!
Function Show-MyMessage{
[System.Windows.Forms.MessageBox]::Show("Repetitive Message.", "Chores.")
}
While(true){
If(condition){
Show-MyMessage
}
If(condition2){
Show-MyMessage
}
}
Edit: Personally I have this function on hand for several of my scripts to use as needed:
Function Show-MsgBox ($Text,$Title="",[Windows.Forms.MessageBoxButtons]$Button = "OK"){
[Windows.Forms.MessageBox]::Show("$Text", "$Title", [Windows.Forms.MessageBoxButtons]::$Button, [Windows.Forms.MessageBoxIcon]::Information) | ?{(!($_ -eq "OK"))}
}
Then I can just call it as needed, like:
Show-MsgBox -Title "You want the truth?" -Text "You can't handle the truth!"
And I've got a pop up with the text and title I want, and an OK button.
Buttons can be specified (there's a pop-up for it in the ISE to give options), and title can be excluded if I am feeling lazy. Only thing I really have to feed it is the message.

Form Gathering Info from Two Other Forms

I have a form that creates a New Work Order. I want to be able to pull the ClientID from the New Client Form or the Main Menu, whichever is open. However I am not getting the desired results:
I have used =IIf(IsNull(Forms![New Client]![txtClientID]), Forms![Main Menu]![txtClientID], Forms![New Client]![txtClientID]) in the Default Value of the Control on the New Work Order Form. I get the correct ID when I go to the form from New Client, but a #Name error when I try to access it from the Main Menu.
What can I do to make it work?
You need to check if the form is loaded, for example (you need to add your own error traps):
Function IsLoaded(ByVal strFormName As String) As Boolean
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
However, it may be easier to use OpenArgs ( http://msdn.microsoft.com/en-us/library/office/ff820845(v=office.15).aspx )
In which case you could say something like:
If IsNull(Me.OpenArgs) Then
MsgBox "No openargs"
Else
Me.txtClientID = Me.Openargs
End If
Or even use Openargs to set the default value.

ABAP: Event CONTEXT_MENU_SELECT of CL_SIMPLE_TREE_MODEL - can't fire it

I have an instance of CL_SIMPLE_TREE_MODEL, I managed to trigger and handle the CONTEXT_MENU_REQUEST event, and I build my context menu.
I added my functions the way I wanted.
Problem is, when I select one of the options from my context menu, nothing happens. In other words, the program flow doesn't go inside the handler for CONTEXT_MENU_SELECT.
I'm of course assuming this event is fired when I click on a function in the context menu.
I found official documentation, but only for the "default context menu" that you access with Shift+F10, that needs certain subroutines in the program in order to fire.
What I did:
I did define and implement a method that is a handler for that event.
I did set the handler for the event at the same place I set the handler for the CONTEXT_MENU_REQUEST event
I did NOT register the event with the SET_REGISTERED_EVENTS because there is NO ID defined in the class attributes for that event - such as there was for the CONTEXT_MENU_REQUEST event.
The code:
REPORT.
CLASS lcl_tree_handler DEFINITION.
PUBLIC SECTION.
METHODS:
pbo,
on_ctx_menu_request FOR EVENT node_context_menu_request OF cl_simple_tree_model
IMPORTING node_key menu sender, "TYPE TM_NODEKEY CL_CTMENU
on_ctx_menu_select FOR EVENT node_context_menu_select OF cl_simple_tree_model
IMPORTING node_key fcode. "TYPE TM_NODEKEY SY-UCOMM
DATA:
po_tree_model TYPE REF TO cl_simple_tree_model,
gt_tree TYPE TABLE OF treemsnodt,
control TYPE REF TO cl_gui_control.
ENDCLASS.
CLASS lcl_tree_handler IMPLEMENTATION.
METHOD pbo.
DATA: lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
FIELD-SYMBOLS <gs_tree> TYPE treemsnodt.
CHECK po_tree_model IS NOT BOUND.
CREATE OBJECT po_tree_model
EXPORTING
node_selection_mode = po_tree_model->node_sel_mode_single.
APPEND INITIAL LINE TO gt_tree ASSIGNING <gs_tree>.
<gs_tree>-node_key = 'Node key 1'.
<gs_tree>-text = 'First node'.
<gs_tree>-isfolder = 'X'.
APPEND INITIAL LINE TO gt_tree ASSIGNING <gs_tree>.
<gs_tree>-node_key = 'Node key 2'.
<gs_tree>-relatkey = 'Node key 1'.
<gs_tree>-relatship = cl_tree_model=>relat_last_child.
<gs_tree>-text = 'First child'.
po_tree_model->add_nodes(
node_table = gt_tree ).
ls_event-eventid = cl_simple_tree_model=>eventid_node_context_menu_req.
ls_event-appl_event = 'X'. "tried with space too
APPEND ls_event TO lt_events.
CALL METHOD po_tree_model->set_registered_events
EXPORTING
events = lt_events.
SET HANDLER on_ctx_menu_request FOR po_tree_model.
SET HANDLER on_ctx_menu_select FOR po_tree_model.
po_tree_model->create_tree_control(
EXPORTING
parent = cl_gui_container=>screen0
IMPORTING
control = control ).
ENDMETHOD.
METHOD on_ctx_menu_request. "I initialize the context menu object here.
DATA: lt_chidren_keys TYPE treemnotab,
ls_child_key TYPE tm_nodekey,
lv_text TYPE gui_text.
CALL METHOD sender->node_get_children
EXPORTING
node_key = node_key
IMPORTING
node_key_table = lt_chidren_keys
EXCEPTIONS
OTHERS = 2.
LOOP AT lt_chidren_keys INTO ls_child_key.
lv_text = ls_child_key.
CALL METHOD menu->add_function
EXPORTING
fcode = 'ONE'
text = lv_text
ftype = 'B'.
ENDLOOP.
menu->add_separator( ).
CALL METHOD menu->add_function
EXPORTING
fcode = 'ALL'
text = 'All the work groups'
ftype = 'W'.
ENDMETHOD.
METHOD on_ctx_menu_select.
BREAK-POINT. "tried actual code here too.
ENDMETHOD.
ENDCLASS.
DATA: go_tree_handler TYPE REF TO lcl_tree_handler.
PARAMETERS dummy.
INITIALIZATION.
CREATE OBJECT go_tree_handler.
AT SELECTION-SCREEN OUTPUT.
go_tree_handler->pbo( ).
AT SELECTION-SCREEN ON EXIT-COMMAND.
go_tree_handler->control->free( ).
The tree is displayed, on right click the context menu appears.
But nothing fires when I chose a menu item. Am I missing something ?
The function types you specify (ftype = 'W' and 'B') are not supported (check the fixed values of the underlying domain CUA_FUNTYP). In that case, nothing happens.
The classic solution is to use ftype = ' ' (normal function):
LOOP AT lt_chidren_keys INTO ls_child_key.
lv_text = ls_child_key.
CALL METHOD menu->add_function
EXPORTING
fcode = 'ONE'
text = lv_text
ftype = ' '.
ENDLOOP.
menu->add_separator( ).
CALL METHOD menu->add_function
EXPORTING
fcode = 'ALL'
text = 'All the work groups'
ftype = ' '.
The possible ftype values are (source: domain CUA_FUNTYP):
' ' : Normal function
'H' : Help function (PROCESS ON HELP REQUEST)
'S' : System function (handled directly by DYNP)
'T' : Transaction call (LEAVE TO TRANSACTION)
'E' : Access modules for 'AT EXIT COMMAND' -> /E as prefix
'I' : Include menu (replaced at runtime - not supported)
'N' : 'AT EXIT COMMAND' Function, > DYNP > /N as Prefix
Remark: the code in the first version of the question was missing the registering of the second event handler SET HANDLER go_tree_handler->on_ctx_menu_select FOR po_tree_model. (now it's okay)