cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Changing fields using Triggers

SOLVED
Highlighted
Level 7

Changing fields using Triggers

Hello,

I am trying to change a field value of a requirement based on if any of the subsection requirements has been edited (Pick list value changed). I am trying to do this using a trigger but I am unsure how to do so. I thought that we are only able to change field values in the same requirement. Based on this, the only way I could see to do this is by pulling information from a relationship field (contained by) and changing the field value through this relationship field. Is this possible? I tried implementing this using the command "getNewRelationshipFieldBeans" and then running an abort command to display what information I pull from the field but what I receive is "[Lmks.ci.server.engine.LocalTriggerManager$ScriptRelationshipBean;@128b7461". Is there another way to accomplish this (easier way)? Is this even possible (I hope so)? I am using Integrity 11.2. I really appreciate your help. Please let me know if there is any more information required. Thanks. 

 

Best Regards,

Taral

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Changing fields using Triggers

You can make changes on a different item in the triggers. To do so, you need to get a deltaBean for that item.

 

Once you have the value for the Contained By field, get the deltaBean for that item. For example:

containedDelta = serverBean.getIssueDeltaBean(ItemID);

 

Then you can change the field values using the methods in the deltaBean, such as setFieldValue.

From the Javadocs for IssueDeltaBean:

 


If you are trying to modify other issues, you can only do it thru the pre-event trigger. The order needs to be expanded upon in that case:

  • Transaction
  • PRE-Trigger Chain
  • Commit-Transaction
  • POST-Trigger Chain
Note that the triggers become chains of triggers. If a PRE-Trigger attempts to modify another issue (via theLocalTriggerManager.ScriptServerBean.getIssueDeltaBean(int) method) or create another issue (via the LocalTriggerManager.ScriptServerBean.postNewIssue(java.lang.String) method) (called the secondary issue) the secondary issue is added to a list of issues that become part of the current transaction. At this point, either all of the modifications made to all of the issues must succeed, or none of them. This means that any PRE-triggers for the secondary issue must also run, and are subject to the same rules as the triggers running for the primary issue. 

 


JavaDocs for the triggers are available by following the Event Trigger Java Documentation link from your Integrity Server homepage.

 

4 REPLIES 4

Re: Changing fields using Triggers

You can make changes on a different item in the triggers. To do so, you need to get a deltaBean for that item.

 

Once you have the value for the Contained By field, get the deltaBean for that item. For example:

containedDelta = serverBean.getIssueDeltaBean(ItemID);

 

Then you can change the field values using the methods in the deltaBean, such as setFieldValue.

From the Javadocs for IssueDeltaBean:

 


If you are trying to modify other issues, you can only do it thru the pre-event trigger. The order needs to be expanded upon in that case:

  • Transaction
  • PRE-Trigger Chain
  • Commit-Transaction
  • POST-Trigger Chain
Note that the triggers become chains of triggers. If a PRE-Trigger attempts to modify another issue (via theLocalTriggerManager.ScriptServerBean.getIssueDeltaBean(int) method) or create another issue (via the LocalTriggerManager.ScriptServerBean.postNewIssue(java.lang.String) method) (called the secondary issue) the secondary issue is added to a list of issues that become part of the current transaction. At this point, either all of the modifications made to all of the issues must succeed, or none of them. This means that any PRE-triggers for the secondary issue must also run, and are subject to the same rules as the triggers running for the primary issue. 

 


JavaDocs for the triggers are available by following the Event Trigger Java Documentation link from your Integrity Server homepage.

 

Re: Changing fields using Triggers

Hello,

Thank you for your response. I don't quite understand how to use the command "containedDelta = serverBean.getIssueDeltaBean(ItemID);". How would I use this to change a field value in a different Item ID. Would I go back to the relationship and implement a change there or would I use the serverBean command to change the field directly. If I use the command "setFieldValue", how would I set the values so that it changes the field in different item.

Thanks.

Re: Changing fields using Triggers

In this case, you have two delta beans. One for the item that is being edited - this one you get by using "bsf.lookupBean("imIssueDeltaBean", and a second one for the other item that you want to modify, which you get by using "serverBean.getIssueDeltaBean(ItemID)". 

 

What item is updated depends on which delta bean you are using to set the fields. 

 

For example:

//Get the server bean
serverBean = bsf.lookupBean("imServerBean");

//Get the delta bean for the item the user is modifying. delta = bsf.lookupBean("imIssueDeltaBean");

delta is the IssueDeltaBean for the item currently being edited by the user. If you want to update or get fields on that item, you use this delta bean (delta).

 

To update the item in the Contained By relationship, you need to get a second delta bean.

// Get value of contained By relationship. Output is array of integers
ContainedBy = delta.getNewRelatedIssues("Contained By");

// There should only be one value for Contained By. Get the Item ID
If ContainedByItemID = ContainedBy[0];

// Get the deltaBean for the Contained By item:
ContainedDelta = serverBean.getIssueDeltaBean(ContainedByItemID);

If you want to update fields in the Contained By item, you would use this delta bean (ContainedDelta).

 

Re: Changing fields using Triggers

I finally understand how this works. Thank you very much for the great explanation and all your help.

Thanks.