Skip to main content
Question

Mass update using another table


Forum|alt.badge.img+6
  • Do Gooder (Partner)
  • 21 replies

Hi.

I need to update multiple contract statuses depending on another contract’s status.

The solution im trying to use is having a table I created named c_contract_link where I list contracts that should be cancelled when the primary contract gets cancelled.

Now im trying to mass update on the contract table using the values from the c_contract_link table.

 

 <perform_batch>
  <sequential_dependent>

<mass_update_contract result_name="link_select">
<hierarchy_select>
  <primary_table>c_contract_link</primary_table>
  <attrs>
    <attr>c_contract_link.linked_contract_id</attr>
  </attrs>
  <from>
    <table>contract</table>
  </from>
  <where>
    <data_constraint>
      <constraint>
        <left_operand>c_contract_link.contract_id</left_operand>
        <operator>eq</operator>
        <right_operand>@contract_id</right_operand>
      </constraint>
      <constraint>
        <left_operand>c_contract_link.cancel_with_primary</left_operand>
        <operator>eq</operator>
        <right_operand>Y</right_operand>
      </constraint>
    </data_constraint>
    <join_constraint>
      <constraint>
        <left_operand>contract.contract_id</left_operand>
        <operator>equi</operator>
        <right_operand>c_contract_link.contract_id</right_operand>
      </constraint>
    </join_constraint>
  </where>
</hierarchy_select>
  <contract>
    <contract_id xpath_node="//c_contract_link_hierarchy_select_result[@result_name='link_select']/c_contract_link/linked_contract_id" />
    <contract_version>1</contract_version>
    <contract_status>CANCEL</contract_status>
    <user_def5>@user_def5</user_def5>
    <cancelled_dt>@cancelled_dt</cancelled_dt>
    <update is_initialized="True"/>
  </contract>
  <transaction_size>100</transaction_size>
  <synchronous>Y</synchronous>
</mass_update_contract>

  </sequential_dependent>
</perform_batch>

 

 

This gives me an error:

<perform_batch_result>
  <mass_update_contract_result result_name="link_select">
    <result type="Exception">
      <error>
        <application_error>
          <severity>ERROR</severity>
          <message>The rows returned from the query are for the c_contract_link table but the mass update message is for the contract table.  Mass update cannot be performed.</message>
        </application_error>
      </error>
    </result>
  </mass_update_contract_result>
</perform_batch_result>

 

Is it possible to use the results from one table to mass update another table?

11 replies

Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • 1168 replies
  • May 8, 2025

Forum|alt.badge.img+6
  • Author
  • Do Gooder (Partner)
  • 21 replies
  • May 9, 2025
Shneor Cheshin wrote:

Thanx for the response.

Those dont answer my question.


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • 1168 replies
  • May 9, 2025

@Fluffy 

Try changing the select to be the contract, not the contract link.

You do not need to provide the ID as XPath, it is derived from the select itself.

Cheers!


Forum|alt.badge.img+6
  • Author
  • Do Gooder (Partner)
  • 21 replies
  • May 10, 2025

If I do that, it just returns the contract_id twice. The problem is I need the linked contract id. The contract table will only return the contract id.


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • 1168 replies
  • May 11, 2025

@Fluffy 

According to your join constraint, it is the same value.

      <constraint>
        <left_operand>contract.contract_id</left_operand>
        <operator>equi</operator>
        <right_operand>c_contract_link.contract_id</right_operand>
      </constraint>

And c_contract_link is used for the where constraint.

Not sure what the problem you are facing is.

Cheers!


Forum|alt.badge.img+6
  • Author
  • Do Gooder (Partner)
  • 21 replies
  • May 12, 2025

@Shneor Cheshin

Im just not sure how I should format the hierarchy select to get the linked contract id from the c_contract_link table so that I can mass update the contract id according to the results of that select. I want to use this in a BR triggered by the contract table.


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • 1168 replies
  • May 12, 2025

@Fluffy 

Try the following (Did not run this, so might be some syntax issues)

<mass_update_contract>
  <hierarchy_select>
    <primary_table>contract</primary_table>
    <attrs>
      <attr>contract.contract_id</attr>
    </attrs>
    <from>
      <table>contract</table>
      <table>c_contract_link</table>
    </from>
    <where>
      <data_constraint>
        <constraint>
          <left_operand>c_contract_link.cancel_with_primary</left_operand>
          <operator>eq</operator>
          <right_operand>Y</right_operand>
        </constraint>
        <constraint>
          <left_operand>contract.contract_id</left_operand>
          <operator>eq</operator>
          <right_operand>@contract_id</right_operand>
        </constraint>
      </data_constraint>
      <join_constraint>
        <constraint>
          <left_operand>contract.contract_id</left_operand>
          <operator>equi</operator>
          <right_operand>c_contract_link.contract_id</right_operand>
        </constraint>
      </join_constraint>
    </where>
  </hierarchy_select>
  <contract>
    <user_def5>@user_def5</user_def5>
    <contract_status>CANCEL</contract_status>
    <contract_version>1</contract_version>
    <cancelled_dt>@cancelled_dt</cancelled_dt>
    <update />
  </contract>
  <transaction_size>1</transaction_size>
  <synchronous>Y</synchronous>
</mass_update_contract>

Cheers!


Forum|alt.badge.img+6
  • Author
  • Do Gooder (Partner)
  • 21 replies
  • May 14, 2025

@Shneor Cheshin 

This simply updates the primary contract, the one that takes the @contract_id value.

Is there a way to maybe use mass insert but force it to update instead perhaps?


Forum|alt.badge.img+6
  • Author
  • Do Gooder (Partner)
  • 21 replies
  • May 14, 2025

Ok, I found a solution that seems to work. I have to use perform_mass_insert instead:

<perform_mass_insert>
  <parameters>
    <select>
     <hierarchy_select>
  <primary_table>c_contract_link</primary_table>
  <attrs>
    <attr>c_contract_link.linked_contract_id</attr>
  </attrs>
  <from>
    <table>contract</table>
  </from>
  <where>
    <data_constraint>
      <constraint>
        <left_operand>c_contract_link.contract_id</left_operand>
        <operator>eq</operator>
        <right_operand>@contract_id</right_operand>
      </constraint>
      <constraint>
        <left_operand>c_contract_link.cancel_with_primary</left_operand>
        <operator>eq</operator>
        <right_operand>Y</right_operand>
      </constraint>
    </data_constraint>
    <join_constraint>
      <constraint>
        <left_operand>contract.contract_id</left_operand>
        <operator>equi</operator>
        <right_operand>c_contract_link.contract_id</right_operand>
      </constraint>
    </join_constraint>
  </where>
</hierarchy_select>
    </select>
    <update>
      <update_contract>
        <contract>
          <contract_id xpath="linked_contract_id" />
          <contract_version>1</contract_version>
          <user_def5>@user_def5</user_def5>
          <contract_status>CANCEL</contract_status>
          <cancelled_dt>@cancelled_dt</cancelled_dt>
          <insert_update />
        </contract>
      </update_contract>
    </update>
  </parameters>
</perform_mass_insert>


Shneor Cheshin
Superhero (Employee)
Forum|alt.badge.img+28
  • Superhero (Employee)
  • 1168 replies
  • May 15, 2025
Fluffy wrote:

@Shneor Cheshin 

This simply updates the primary contract, the one that takes the @contract_id value.

Is there a way to maybe use mass insert but force it to update instead perhaps?

@Fluffy 

  • That is exactly what your original XML is doing.
  • Mass Insert is not a baseline MPM. Unless you have a customisation for that, it will not work.

Cheers!


Forum|alt.badge.img+6
  • Author
  • Do Gooder (Partner)
  • 21 replies
  • May 16, 2025

Ah yea its a customisation. Sorry. Wont work for other people.

But for other people, could someone post an example of a working script for mass update that pulls data from one table and uses the results to update another table?

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings