Post Processing logic on Clicking Save button in Pick related Window on a relationship Tab

We have a Requirement as Following . We have a list of Master Exam list (around 500 Items) . When I go to a Project, I need to perform a subset of exams (e.g 100) out of 500 Master list .For that When I go to Project > Exam Tab>Click on Pick Related , my search screen is showing the list of 500 Master list. After selecting few, when I Click on Save(Green tick) , I would like to create an instance of those selected Master list with different Item Types and connect it to my Project.

Example :
I have Master Exam List
MEL 0000001
MEL 0000002
MEL 0000003

On Project P1> Exam tab > I click on Pick Related .Search screen showing MEL 000001-003 . I select MEL 000001 and 000002 and Click on Save. What I want system to do is create 2 new objects with Item type Project Exam List like

PEL 0000001
PEL 0000002
PEL 0000003

PEL objects should have copied all attributes from Corresponding Source MEL objects.

Is this king of Post Processing logic possible after clicking on save ? If Yes, can someone guide us through the steps?

  • Hi there,

    yes this is certainly possible. If I understand you correctly, you can achieve the functionality you need by implementing an onBeforeAdd (or similar) method on the relationship ItemType between Project and MEL (I'm assuming this is called PMEL from here on).

    One thing to note before I start: I am assuming with "saving" you are referring to saving the changes on the Project after you have added the MELs to it, not the "Confirm selection" tick mark you click when selecting related MELs. Since you are not committing any relationship or property changes on the Project Item to the database before you save it, I do not believe it makes much sense to put the logic on the selection event for related MELs.
    In any case, here's how I would go about implementing the logic triggered onSave of the Project (which is when the relationship items get created, hence onBeforeAdd triggers for PMEL):

    • Create a method that will contain the creation logic for the PEL objects, here I will call it CreatePels
      • For some thoughts on what would be going on in CreatePels, see below
    • Open ItemType PMEL and lock (edit) it
    • Go to the tab "Server Events"
    • Search for and add CreatePels
      • Set "Event" to be "onBeforeAdd"
      • Set "Event Version" to "Version 1"
    • Save, unlock and close ItemType PMEL

    Now, when you save a project after adding MELs to it, CreatePels will trigger and create your corresponding PELs.

    In CreatePels, you have access to the Project ID via this.getProperty("source_id", "") and the MEL ID via this.getProperty("related_id", ""). Via this related_id you would also obtain all the MEL attributes that you need to map to your new PEL. Just be sure not to alter "this" (which is the to-be-added relationship between Project and MEL) and to "return this" at the end of the method.
    Note that for each MEL you add to the Project, CreatePels gets triggered once. So if you add three MELs to your Project, CreatePels gets triggered three times.

    Another thing you could do is put the method on the Project ItemType with event onBeforeUpdate or something similar. In this case, the method would only trigger once, but you'd have to get a hold of the MELs you added to the project in a different way. I find the PMEL approach more straightforward and intuitive.

    Hope this helps,

    C

  • 0 オフライン in reply to cogres

    Thank you so much for detailed response. I will try it and let you know the result .