Simple Event Script

Hi,

I have 10 page 3 ‘Part’ text values (defined at the character set level as numerics) that I would like to sum up in a 11th attribute. Can somebody please share with me an easy way to do this using an event script?

Thank you in advance for any help on this. 

Brad Levitan

Add Comment
7 Answer(s)

Hi Brad,

please take to the code bellow as a seed. It shloud guide you.
My best
Carlos

// ===========================================================================
//
// Author: Carlos Benassi
// Date: 25/10/2016
// Desc: This script generates a number based on the calculation of other 3 number.
// In this example it uses the SubClass names and several Page2 attributes to calculate the result.
//
// Implementation: This script should be run as a Post event on the SubClass Create event
// it can also be tied to the SubClass UpdateTitleBlock event to prevent changes
//
//

import com.agile.agileDSL.ScriptObj.IBaseScriptObj
import com.agile.api.ChangeConstants

void invokeScript(IBaseScriptObj obj) {
// get the change type
changetype = obj.getValueByAttId(ChangeConstants.ATT_COVER_PAGE_CHANGE_TYPE);

// Get the PAGE2 Attributes to calculate the result
// page2.list04 = fit
// page2.list05 = techrisk
// page2.list06 = mktrisk

fit = obj.getValueByAttId(ChangeConstants.ATT_PAGE_TWO_LIST04);
techrisk = obj.getValueByAttId(ChangeConstants.ATT_PAGE_TWO_LIST05);
mktrisk = obj.getValueByAttId(ChangeConstants.ATT_PAGE_TWO_LIST06);

// Create the calculus
score = fit.toInteger() * techrisk.toInteger() * mktrisk.toInteger()

// Update the score values
obj.setValueByAttId(ChangeConstants.ATT_PAGE_TWO_NUMERIC01, Integer.toString(score));

// log to Event Handler Monitor –
// View the log monitor to ensure the action is completing correctly
obj.logMonitor( “Value=” + score);
}

Agile Angel Answered on October 29, 2018.

Just one recommendation from my side will be to handle exceptions if the attributes are blank. Not sure how Groovy handles it, but in Java, I like to use String.valueOf(Integer value) instead of Integer.toString(int value) just in case to avoid unnecessary null pointer exceptions.

on October 29, 2018.

Thank you Swagato

on October 29, 2018.
Add Comment

Thank you very much Carlos, I was just coming back in here to update my question. The challenge I have is actually related to page 3 attributes associated with Quality Change Request, would I still use this example to try and build my sum total.

Again, thank you for the quick response.

Brad

Agile User Answered on October 29, 2018.

Quality Change Request subclass’s Page Three attributes’ base id will remain in QualityChangeRequestConstants class but not if your attributes are Flex ones. If you feel this approach is difficult then instead of using the base id constants you can simply pass the attribute’s API name as the parameters in obj.getValue() method to get that attribute’s value.

on October 29, 2018.
Add Comment

Brad,

take a look, I had no time to test it, but it’s a step further.
Swagoto has a good point as well, I didn’t implement it.

My best
Carlos

import com.agile.agileDSL.ScriptObj.IBaseScriptObj
import com.agile.api.CommomConstants
import com.agile.api.ChangeConstants
import com.agile.api.QualityChangeRequestConstants

void invokeScript(IBaseScriptObj obj) {
// get the change type
changetype = obj.getValueByAttId(QualityChangeRequestConstants.ATT_COVER_PAGE_QCR_TYPE);

// Get the PAGE3 Attributes to calculate the result
// page3.text01 = text01
// page3.text02 = text02
// page3.text03 = text03

text01 = obj.getValueByAttId(CommomConstants.ATT_PAGE_THREE_TEXT01);
text02 = obj.getValueByAttId(CommomConstants.ATT_PAGE_THREE_TEXT02);
text03 = obj.getValueByAttId(CommomConstants.ATT_PAGE_THREE_TEXT03);

// Create the calculus
score = text01.toInteger() + text02.toInteger() + text03.toInteger()

// Update the score values
obj.setValueByAttId(CommomConstants.ATT_PAGE_THREE_TEXT11, Integer.toString(score));

// log to Event Handler Monitor –
// View the log monitor to ensure the action is completing correctly
obj.logMonitor( “Value=” + score);
}

Agile Angel Answered on October 29, 2018.
Add Comment

You guys are awesome, thank you both very much!  I think I am getting close.

Brad

Agile User Answered on October 30, 2018.
Add Comment

Hi,

So I took your code and  changed it to use my selected text attributes. I also updated the ‘import com.agile.api.CommomConstants’ to ‘import com.agile.api.CommonConstants’, but I get the error in the attachment. Any ideas? 

Again, thank you for your help. Its much appreciated.

Brad

Agile User Answered on October 30, 2018.
Add Comment

Actually, I got it to validate by replacing the double quotes around ‘Value+’with single quotes. Testing now.

Agile User Answered on October 30, 2018.
Add Comment

Hi, so it compiles cleanly, but still doesn’t add up the text fields. This is what I see in the history page. Any thoughts?

Brad

Agile User Answered on October 30, 2018.

do you have the stacktrace printed in the logs throwing some exception?

on November 1, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.