Menu

Update Org_ID in Incident

2021-06-15
2023-11-07
  • Karthik Reddy

    Karthik Reddy - 2021-06-15

    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

    <?xml version="1.0" encoding="UTF-8"?>
    <itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
        <classes>
            <class id="Incident" _delta="merge">
                <fields>
                    <field id="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>
                <method id="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>
                 <method id="AfterInsert" _delta="define">
                          <static>false</static>
                          <access>protected</access>
                          <type>Overload-DBObject</type>
                          <code><![CDATA[   protected function AfterInsert()
                            {
                                parent::AfterInsert();
                        $this->SetOrgId();
    
                    }]]></code>
                    </method>
                     <method id="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
  • Pierre Goiffon

    Pierre Goiffon - 2021-06-23

    Hello,

    Take a look at the CRUD stack : you should overwrite different hooks than AfterInsert/AfterUpdate. Maybe OnInsert/OnUpdate ?

     
    👍
    1
  • Karthik Reddy

    Karthik Reddy - 2021-06-24

    Thanks Pierre. I am able do this successfully with iApplicationObjectExtension and it worked in updating the org_id based on service.

     
    • Youssef Gadelrab

      Can you share with the community the extension you wrote for updating the org_id based on service?

       
  • Pierre Goiffon

    Pierre Goiffon - 2021-06-24

    Perfect, thanks for your feedback !

     

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.