Tutorial: Module Customizing (Level 3)
Information
- This module workflow
- builds on the Test Module created in Module Workflow: Level 1 and expanded on in Module Workflow: Level 2.
- gives a first insight into customizing with Python.
- Working with this workflow requires the knowledge provided in Module Workflow: Level 1 and Module Workflow: Level 2.
- The individual steps in this workflow build on each other.
- Python basic 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 this link is clicked, a message is displayed.
- If it is confirmed with Yes, another module is opened in which all the marked projects are displayed.
- If it is confirmed with No, the project on which the link was clicked is marked.
- If this link is clicked, a message is 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 title
- 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: Creating a macro module for module creation
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 thus cannot 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
# In order to be able to read the module ID from the global settings
# the global_setting Python module needs to be imported.
from ppms.global_setting import get_global_setting_value
# Definition of the module object
mod_obj = ppms.get_target_module()
# Definition of the module ID. By means of the self-defined Python ID
# it is read from the global settings.
target_mod_id = get_global_setting_value("Python_ID_Projektdatenblatt", 'alpha120')
#Read project ID of the record which is opened on the link.
pr_id = ppms.get_context_df().get_record().get_df ("pr_id").get_raw_value()
# Set variable _L30_ for the module which is opened
mod_obj.set_new_L_var(30, [pr_id])
#Open the module
mod_obj.open_module(target_mod_id)
PY
- Save.
Tips
- Instead of
pr_id = ppms.get_context_df().get_record().get_df("pr_id").get_raw_value()
PY
- the following (shorter) line can be used:
pr_id = ppms.get_context_df().get_record().pr_id.get_raw_value()
PY
- 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()
PY
Define Link
Procedure
- Define the Project title 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 the Module
Procedure
- Start the Test Module module.
- Click on the project title 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 confirms the message with Yes, the Project Data Sheet module is opened.
- If the user confirms the message with No, 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 store a Python ID:
- Select Insert Global Settings from the context menu.
- In the Class listbox, select the requested class, here Dialog message ID.
- In the Alpha (120) field, enter the dialog message ID.
- 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 of the module ID and the dialog message 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])
# Output of the dialog message
ppms.ui_message_id(dialog_id)
# If the user clicks on "Yes" ("if"), the module is opened,
# otherwise ("else") the record is marked.
if ppms.msg_pop().get_reply() == 1:
mod_obj.open_module(target_mod_id)
else:
ppms.get_context_df().get_record().mark()
PY
Test the Module
Procedure
- Start the Test Module module.
- 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 the project on which the link was clicked 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=ppms_cu.Helper.get_global_setting("Python_ID_Projektdatenblatt").alpha120.get_value()
dialog_id=ppms_cu.Helper.get_global_setting("Python_ID_Dialogmeldung").alpha120.get_value()
#Definition of a list containing all the marked records in the project data area.
#When no record is marked, this list is blank.
marked_records = ppms.get_context_df().get_record().get_da().get_marked_records()
#Definition of new blank list
project_list=[]
# Is at least one record available in the "marked_records" list
# for every record in this list the project ID is read and written into the "project_list" list.
# Additionally, the project ID of the record on which the link was activated is written
# into the list.
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())
# If the "marked_records" list is blank, the project ID of the record on which the link was activated
# is written into the list.
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()
PY
Test the 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 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 builds 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 @L30 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.
- The
- Please note:
from ppms.global_setting import get_global_setting_value
mod_obj = ppms.get_target_module()
# Definition of the module and dialog message 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)
# Open the task data sheet
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)
# Execute the "get_tasks" method with the "pr_id" transfer parameter
# This method is defined in the next module in the task data sheet.
task_mod_obj.get_tasks(pr_id)
else:
ppms.get_context_df().get_record().mark()
PY
Change the Macro in the Task Data Sheet
Objective
- The milestones of the project that was opened by clicking 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.
- Please note: The
# Definition of the get_tasks method
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():
# Provides the "get_tasks" method for the module object.
od_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
PY
Test the 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 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 are displayed.
- If you click on No, the project on which the link was clicked is marked.
- If you click on Yes, the project data sheet is opened and all marked projects and the project on which the link was clicked are displayed.