Tutorial: Module Customizing (Level 3)
Information
- This module workflow
- is based on the module created in the Tutorial: Module Workflow (Level 1) and expanded in the Tutorial: Module Workflow (Level 2) (Test Module).
- Provides a first insight into customizing with Python.
- This workflow is based on the knowledge provided in Tutorial: Module Workflow (Level 1) and Tutorial: Module Workflow (Level 2).
- The individual steps in this workflow are based on the previous steps.
- Basic Python knowledge is required. For the use of individual Python functions see also Python API.
Task 1
Objective
- In Test Module module, a field is defined as link.
- If you click on this link, a message will be displayed.
- If it is answered with Yes, another module is opened in which all the marked projects are displayed.
- If it is answered with No, the project on which the link was clicked is marked.
- If you click on this link, a message will be displayed.
Step 1: Preparation
Information
- For this task, another module must be customized (procedure as described in Module Workflow Level 1):
- Module title: Project Data Sheet
- create a data area with the following data fields and settings (as described in Module Workflow: Level 1 and assign it to the module:
- DDI: 001001 Project ID
- DI001001 Project ID and DI000690 Project name
- Store @L30 in Filter from on the Project ID data field.
- Insert a macro that filters within the on_initial_focus() Python function (for procedure see here).
- Additionally, in the Project data area of the Test Module module, remove filter criterion 4811 from the Filter from field.
Step 2: Create a macro module for module call
Objectives
- To create a macro module that opens the Project Data Sheet
- To provide this macro module on a data field on the Test Module module.
Store the Project Data Sheet module in the Global Settings
Procedure
- Open the Global Settings module.
- Open Customizer → Master Data → Global Settings or
- activate the Global Settings tab (the submodule) in the Modules panel.
- For the Project Data Sheet module, create a new global setting and store a Python ID.
- Select Insert → Global Settings from the context menu.
- Select the requested class, here Module ID, in the Class listbox.
- In the Alpha (120) field, enter the module ID of the project data sheet.
- In the Python ID field, define a Python ID, e.g. pr_datasheet.
- Save.
Create the Macro Module
Procedure
- Create a macro module (module with class = 6).
- Open the Python editor by clicking on the Edit python macro button. A template is copied automatically.
- This template is planned for modules with class = 4, and can thus not be deleted.
- Store the following macro:
- Please note: Entry
Python_ID_ProjectDataSheet
needs to be replaced by the value from the Python ID field of the newly created global setting of the project data sheet.
- Please note: Entry
#Um die Modul-ID aus den globalen Einstellungen auslesen zu koennen
#muss das Python-Modul global_setting importiert werden.
from ppms.global_setting import get_global_setting_value
# Definition des Modul-Objekts
mod_obj = ppms.get_target_module()
# Definition der Modul-ID. Diese wird mit Hilfe der selbst definierten Python-ID
# aus den globalen Einstellungen ausgelesen.
target_mod_id = get_global_setting_value("Python_ID_Projektdatenblatt", 'alpha120')
#Auslesen der Projekt-ID des Datensatzes auf dem der Link aufgerufen wird
pr_id = ppms.get_context_df().get_record().get_df("pr_id").get_raw_value()
# Variable L30 fuer das Modul, das aufgerufen wird, setzen
mod_obj.set_new_L_var(30, [pr_id])
#Modul aufrufen
mod_obj.open_module(target_mod_id)
- Save.
Tips
- Instead of
pr_id = ppms.get_context_df().get_record().get_df("pr_id").get_raw_value()
- you can also use the following (shorter) line:
pr_id = ppms.get_context_df().get_record().pr_id.get_raw_value()
- When the link on the data field that is to be read (in this case: when customizing the link on the Project ID field), the following line can be used for reading:
pr_id = ppms.get_context_df().get_raw_value()
Define Link
Procedure
- Define the Project name DI as a link (DF behavior = e4) and store the ID of the newly created macro module in the Action ID field in the Test Module module (Project data area).
- Save.
Test Module
Procedure
- Start the Test Module module.
- Click on the project name of a project: The Project Data Sheet module is opened and the project on which the link was clicked is displayed.
Step 3: Add a Dialog Message
Objective
- The following dialog message should appear before the Project Data Sheet is opened: Do you really want to edit this project?
- If the user answers the message with Yes: the Project Core Data module is opened.
- If the user answers the message with No: If the project record of the selected project is marked.
Create Dialog Message
Procedure
- Open Customizer → Master Data → Dialog Messages.
- Insert a new dialog message line by right-clicking and selecting Insert → Dialog Message.
- Enter Do you really want to edit this project? in the Dialog message field.
- Select 1 as a value in the Output type field.
- Select Default button = 1 and Button type = 3.
- Save.
Store the Dialog Message ID in the Global Settings
Procedure
- Open the Global Settings module.
- Open Customizer → Master Data → Global Settings or
- activate the Global Settings tab (the submodule) in the Modules panel.
- For the dialog message, create a new global setting and specify a Python ID:
- Select Insert → Global Settings from the context menu.
- In the Class listbox, select the requested class, here Dialog message ID.
- Enter the dialog message ID in the Alpha (120) field.
- In the Python ID field, define a Python ID, e.g. pr_msg_box.
- Save.
Adapt the Macro of the Macro Module
Procedure
- Open the macro module in the Python editor and adjust it in the following way:
- Please note:
from ppms.global_setting import get_global_setting_value
mod_obj = ppms.get_target_module()
# Definition der Modul-ID und der Dialogmeldungs-ID
target_mod_id = get_global_setting_value("Python_ID_Projektdatenblatt", 'alpha120')
dialog_id = get_global_setting_value("Python_ID_Dialogmeldung", 'alpha120')
pr_id = ppms.get_context_df().get_record().get_df("pr_id").get_raw_value()
mod_obj.set_new_L_var(30, [pr_id])
# Ausgabe der Dialogmeldung
ppms.ui_message_id(dialog_id)
# Klickt der Anwender auf "Ja" ("if"), wird das Modul aufgerufen,
# sonst ("else") wird der Datensatz markiert.
if ppms.msg_pop().get_reply() == 1:
mod_obj.open_module(target_mod_id)
else:
ppms.get_context_df().get_record().mark()
Test Module
Procedure
- Start the Test Module module.
- Click on the project name of a project
- The Do you really want to edit the project? dialog message is displayed.
- If you click on Yes, the project data sheet is opened and the project on which the link was clicked on is displayed.
- If you click on No, the project on which the link was clicked is marked.
Step 4: Display all Marked Projects
Objective
- All of the marked projects are to be displayed in the Project Data Sheet module.
- If no project has been marked, the project on which the link was clicked is to be displayed.
Adapt the Macro of the Macro Module
Procedure
- Open the macro module in the Python editor and adjust it in the following way:
- Please note:
from ppms.global_setting import get_global_setting_value
mod_obj = ppms.get_target_module()
target_mod_id = get_global_setting_value("Python_ID_Projektdatenblatt", 'alpha120')
dialog_id = get_global_setting_value("Python_ID_Dialogmeldung", 'alpha120')
#Definition einer Liste der markierten Datensaetze im Projektdatenbereich
#Ist kein Datensatz markiert, ist diese Liste leer
marked_records = ppms.get_context_df().get_record().get_da().get_marked_records()
#Definition einer neuen leeren Liste
project_list=[]
# Ist in der Liste "marked_records" mindestens ein Datensatz vorhanden, wird fuer jeden Datensatz in der
# Liste "marked_records" die Projekt-ID ausgelesen und in die Liste "project_list" geschrieben.
# Zusaetzlich wird die Projekt-ID des Datensatzes, auf dem der Link aktiviert wurde, in die
# Liste geschrieben.
if len(marked_records) > 0:
for record in marked_records:
cur_pr_id = record.pr_id.get_raw_value()
project_list.append(cur_pr_id)
project_list.append(ppms.get_context_df().get_record().pr_id.get_raw_value())
# Ist die Liste "marked_records" leer, wird die Projekt-ID des Datensatzes, auf dem der Link aktiviert
# wurde, in die Liste geschrieben.
else:
project_list.append(ppms.get_context_df().get_record().pr_id.get_raw_value())
mod_obj.set_new_L_var(30, project_list)
ppms.ui_message_id(dialog_id)
if ppms.msg_pop().get_reply() == 1:
mod_obj.open_module(target_mod_id)
else:
ppms.get_context_df().get_record().mark()
Test Module
Procedure
- Start the Test Module module.
- Mark several projects and click on the project name of a project
- The Do you really want to edit the project? dialog message is displayed.
- If you click on Yes, the project data sheet is opened and all marked projects and the project on which the link was clicked on are displayed.
- If you click on No, the project on which the link was clicked is marked.
Task 2
Objectives
- Furthermore, the Task Data Sheet in which all milestones of the project on which the link was clicked are displayed are to be opened from the Test Module.
- The module is to be opened behind the Project Data Sheet.
Note
- This task is based on task 1.
Step 1: Preparation
Information
- For this task, another module must be customized (procedure as described in Module Workflow Level 1):
- Module title: Task Data Sheet
- create a data area with the following data fields and settings (as described in Module Workflow: Level 1 and assign it to the module:
- DDI: 001098 Task ID
- 001098 Task ID and 000807 Task name
- On the Task ID data field, store @L11 in Filter from.
- Insert a macro that filters within the on_initial_focus() Python function (see here).
Step 2: Open the Task Data Sheet
Store the Task Data Sheet in the Global Settings
Procedure
- Open the Global Settings module.
- Open Customizer → Master Data → Global Settings or activate the Global Settings tab (submodule) in the Modules panel.
- For the Task Data Sheet module, create a new global setting and store a Python ID:
- Select Insert → Global Settings from the context menu.
- Select the requested class, here Module ID, in the Class listbox.
- Enter the module ID of the task data sheet in the Alpha (120) field.
- In the Python ID field, define a Python ID, e.g. task_datasheet.
- Save.
Adapt the Macro Module
Procedure
- Open the macro module in the Python editor and adjust it the following way:
- Please note:
- The Python_ID_Projektdatenblatt entry must be replaced by the value from the Python ID field of the global setting of the project data sheet.
- The Python_ID_Dialogmeldung entry must be replaced by the value from the Python ID field of the newly created global setting of the dialog message.
- The Python_ID_Vorgangsdatenblatt entry must be replaced by the value from the Python ID field of the global setting of the task data sheet.
- Please note:
from ppms.global_setting import get_global_setting_value
mod_obj = ppms.get_target_module()
# Definition der Modul-IDs und der Dialogmeldungs-ID
target_mod_id = get_global_setting_value("Python_ID_Projektdatenblatt", 'alpha120')
dialog_id = get_global_setting_value("Python_ID_Dialogmeldung", 'alpha120')
target_task_mod_id = get_global_setting_value("Python_ID_Vorgangsdatenblatt", 'alpha120')
marked_records = ppms.get_context_df().get_record().get_da().get_marked_records()
pr_id = ppms.get_context_df().get_record().pr_id.get_raw_value()
pr_list = [pr_id]
if len(marked_records) > 0:
for record in marked_records:
cur_pr_id = record.pr_id.get_raw_value()
pr_list.append(cur_pr_id)
mod_obj.set_new_L_var(30, pr_list)
ppms.ui_message_id(dialog_id)
if ppms.msg_pop().get_reply() == 1:
pr_mod_obj = mod_obj.open_module(target_mod_id, forced_status=1)
# Oeffnen des Vorgangsdatenblattes
task_mod_obj = pr_mod_obj.open_module(target_task_mod_id, forced_status=2, dock_to_module = pr_mod_obj.get_uid(), foreground=0, focus=0)
# Ausfuehren der Methode "get_tasks" mit dem Uebergabeparameter "pr_id"
# Diese Methode wird im naechsten Modul im Vorgangsdatenblatt definiert.
task_mod_obj.get_tasks(pr_id)
else:
ppms.get_context_df().get_record().mark()
Change the Macro in the Task Data Sheet
Objective
- The milestones of the project which is opened by clicking on the link is to be displayed.
Details
- A
get_tasks
method is defined, which writes the tasks of the project specified with Milestone = 2 to a list (task_list). - This list is written in the @L11 list variable.
Procedure
- Create a new record in the SQL Statements module and rename the statement. Subsequently, create an SQL procedure code with the following SQL Statement:
Select DI001098 FROM DT463 WHERE DI001097=
'{0}' AND DI006786='{1}'
- Change the macro in the Task Data Sheet in the following way:
- Please note: The SQL Statement ID entry must be replaced by the value from the Statement field of the newly created statement.
# Definition der Methode get_tasks
def get_tasks(pr_id):
value=2
sql_query=ppms.get_query("SQL-Statement-ID").format(pr_id,value)
sql_query_result = ppms.db_select(sql_query)
task_list=[]
for record in sql_query_result:
task_list.append(record[0])
mod_obj.set_current_L_var(11, task_list)
mod_obj = ppms.get_target_module()
def on_load():
# Stellt die Methode "get_tasks" dem Modulobjekt zur Verfuegung
mod_obj.get_tasks = get_tasks
def on_initial_focus():
mod_obj.menu(12)
def on_focus():
pass
def on_reset():
on_initial_focus()
def on_before_mv_switch(old_mv, new_mv):
pass
def on_after_mv_switch(old_mv, new_mv):
pass
Test Module
Procedure
- Start the Test Module module.
- Mark several projects and click on the project title of a project.
- The Do you really want to edit the project? dialog message is displayed.
- If you click on Yes:
- the project data sheet is opened and all marked projects and the project on which the link was clicked on are displayed.
- Additionally, the Task Data Sheet is displayed behind the Project Data Sheet. In this module the milestones of the project on which the link was clicked on are displayed.
- If you click on No, the project on which the link was clicked is marked.
- If you click on Yes: