Menu

Set field value using a query

2023-10-24
2023-11-24
  • Marco Musolesi

    Marco Musolesi - 2023-10-24

    Hello,

    I would like to set a field value using a query.

    Example I have a FunctionCi with with a owner person and I want a field "escaltion" that needs to be the manager of the person that I choose as CI owner

    how can I do?

    thanks a lot

     
  • Jeffrey Bostoen

    Jeffrey Bostoen - 2023-10-24

    Mind that unless you directly manipulate the SQL database; iTop's own OQL query language does NOT allow you to update data; only to query data.

     
  • Marco Musolesi

    Marco Musolesi - 2023-10-24

    Hi Jeffrey

    I don't really need to manipulate any data, I need to inherit data from a linked object.

    I saw something like this already happen with a native iTop class , but I forgot where I saw it and I am not able to reverse engineer the existing class.
    I am looking for help

    thanks a lot

     
  • Vincent @ Combodo

    In your particular example, just create an ExternalField which retrieve the manager_id of the functionalci owner_id and job done.

     
  • Vincent @ Combodo

    <class id="FunctionalCI" _delta="if_exists">
      <fields>
        <field id="owner_id" xsi:type="AttributeExternalKey" _delta="define">
          <sql>owner_id</sql>
          <target_class>Person</target_class>
          <is_null_allowed>true</is_null_allowed>
          <on_target_delete>DEL_MANUAL</on_target_delete>
        </field>
        <field id="escalation_id" xsi:type="AttributeExternalField" _delta="define">
          <extkey_attcode>owner_id</extkey_attcode>
          <target_attcode>manager_id</target_attcode>
        </field>
      </fields>
     </class>
    
     
  • Marco Musolesi

    Marco Musolesi - 2023-10-24

    Great Vincent!
    this is exactly what I mean and it works with new defined class

    I also tried with delta="redefine" but if fail
    I got : attempting to redeclare the inherited attribute

    field was declared in a parent class as mandatory, and I would like to transform it using your suggested type AttributeExternalField

    Is it possible?

     

    Last edit: Marco Musolesi 2023-10-24
  • Pierre Goiffon

    Pierre Goiffon - 2023-11-24

    Hello,
    Fields can't be redefined in children classes...

     

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.