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!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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 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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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!
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.
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?
You're forgetting to call a method to save your new object. Look for "DBInsert" or "DBWrite".
Thank you so much! Your advice worked, and I fixed it so that it now creates an object.
You're forgetting to call a method to save your new object. Look for "DBInsert" or "DBWrite".