Menu

New Object during State Transition

2024-07-01
2024-07-08
  • Zach Karmel

    Zach Karmel - 2024-07-01

    Hello! I’m currently working on a project in iTop where I’m trying to create a new object during a state transition. Essentially, whenever a user checks out/in a device, it’s meant to create a new object that stores the device id, the dates of check in and check out, and a few other fields. The reason I didn’t implement it simply as a field is because I want to be able to look at all past instances when an object has been checked in or out.

    However, I can’t quite figure out how to create a new object when a stimulus is activated, and I’m not even sure if it’s the best possible way of going about this issue. It exists in PhysicalDevice, but I want to create a new instance of my custom class whenever Check In is pressed

    I’m running into trouble on the best way of implementing this, and any advice would be appreciated!

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2024-07-01

    Interesting question!

    There was an event listener in iTop 3.1 for that, but I noticed in the iTop 3.2 notes that the event listener got removed again.

    However, you could also perhaps create the separate record to keep track of the "check out" / "check in" date and use some event on that object to also update the status of the device itself.

     
    • Zach Karmel

      Zach Karmel - 2024-07-08

      Thanks for your reply! I wound up trying to create my own LifecycleAction method in the PhysicalDevice class; the code compiles, and it's integrated into the lifecycle of PC class which should inherit this method, but I'm confused why no new CheckInOut objects appear when the proper stimulus is applied

      Here's my method in PhysicalDevice:
      <method id="CreatePCheckOutOnTransition" _delta="define">
      <static>false</static>
      <access>public</access>
      <type>LifecycleAction</type>
      <![CDATA
      function CreatePCheckOutOnTransition($orgId, $contactId, $physId)
      {
      $oPCheck = new PersonCheckInOut(); //My custom class of object
      $oPCheck->Set('org_id', $orgId);
      $oPCheck->Set('contact_id', $contactId);
      $oPCheck->Set('physicaldevice_id', $physId);
      return true;
      }
      ]>

      </method>

      Here's how I implement it in PC:
      <action>
      <verb>CreatePCheckOutOnTransition</verb>
      <params>
      <param xsi:type="attcode">org_id
      <param xsi:type="attcode">contact_id
      <param xsi:type="attcode">id
      </params>
      </action>

      Even when I apply this stimulus, nothing changes on the list of PersonCheckInOut() objects. If it weren't working, I'd expect there to be an error, but nothing of note happens! Would anyone happen to know why this doesn't work as intended?

       
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2024-07-08

        You're forgetting to call a method to save your new object. Look for "DBInsert" or "DBWrite".

         
        • Zach Karmel

          Zach Karmel - 2024-07-08

          Thank you so much! Your advice worked, and I fixed it so that it now creates an object.

           
          👍
          1
      • Jeffrey Bostoen

        Jeffrey Bostoen - 2024-07-08

        You're forgetting to call a method to save your new object. Look for "DBInsert" or "DBWrite".

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.