I am trying to update the Organization based on selected Service and I have created an extension to show all services in the drop down list. Extension loaded sucessfully. But after Incident is created or updated, org_id is not updated and also no error.
I am not sure what is the issue with the below code, can experts please help to check. Thanks
<?xml version="1.0" encoding="UTF-8"?><itop_designxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"version="1.0"><classes><classid="Incident"_delta="merge"><fields><fieldid="service_id"xsi:type="AttributeExternalKey"><is_null_allowed_delta="redefine">false</is_null_allowed><filter_delta="redefine"><![CDATA[SELECT Service AS s JOIN lnkCustomerContractToService AS l1 ON l1.service_id=s.id JOIN CustomerContract AS cc ON l1.customercontract_id=cc.id WHERE s.status != 'obsolete']]></filter></field></fields><methods><methodid="SetOrgId"_delta="define"><static>false</static><access>public</access><type>Overload-DBObject</type><code><![CDATA[ public function SetOrgId() { //Get Org ID based on Service $sOQL = "SELECT Service AS s JOIN Incident AS I ON I.service_id=s.id WHERE s.status != 'obsolete' AND I.id=:ticket"; $oConnectionSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL), array(), array( 'ticket' => $this->GetKey(), ) ); while($oRequest = $oConnectionSet->Fetch()) { $this->Set('org_id', $oRequest->Get('org_id')); } $this->DBUpdate(); } ]]></code></method><methodid="AfterInsert"_delta="define"><static>false</static><access>protected</access><type>Overload-DBObject</type><code><![CDATA[ protected function AfterInsert() { parent::AfterInsert(); $this->SetOrgId(); }]]></code></method><methodid="AfterUpdate"_delta="define"><static>false</static><access>protected</access><type>Overload-DBObject</type><code><![CDATA[ protected function AfterUpdate() { parent::AfterUpdate(); $this->SetOrgId(); }]]></code></method></methods></class></classes></itop_design>
Regards,
Karthik
Last edit: Karthik Reddy 2021-06-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Community,
I am trying to update the Organization based on selected Service and I have created an extension to show all services in the drop down list. Extension loaded sucessfully. But after Incident is created or updated, org_id is not updated and also no error.
I am not sure what is the issue with the below code, can experts please help to check. Thanks
Regards,
Karthik
Last edit: Karthik Reddy 2021-06-15
Hello,
Take a look at the CRUD stack : you should overwrite different hooks than AfterInsert/AfterUpdate. Maybe OnInsert/OnUpdate ?
Thanks Pierre. I am able do this successfully with iApplicationObjectExtension and it worked in updating the org_id based on service.
Can you share with the community the extension you wrote for updating the org_id based on service?
Perfect, thanks for your feedback !