Groovy - Generate dynamic script based on the edit cells in the data form (E)PBCS
Hello,
Happy new year 2018 to all the readers. May you all have a great year ahead.
Today we will see how groovy can be used to generate script to calculated only on the edited cells (not to be confused with intelligent calculation).
Below is the snippet of the code.
//Get current Data Form
DataGrid curGrid = operation.getGrid()
// Holds the value for the venders that have changed
Set<String> periodList = []
// Iterater which gives you only the edited cells
curGrid.dataCellIterator({DataCell cell -> cell.edited}).each { DataCell cell ->
periodList << cell.getMemberName("Period")
}
// Holds the list of members from the POV – the function returns an array, so this
// parsed the array and places quotes around each member and separates them with a comma
// if cells are edited only then execute the script
if (periodList) {
// convert the list to comma separated value (ex,. if sep, oct and nov are edited the sPeriods will hold value as Sep, Oct, Nov)
String sPeriods = """ "${periodList.join('","')}" """
// Generate the script and assign it to String variable as below
// $ needs to be prefix for variable as show for $sPeriods which will be replaced with Sep, Oct, Nov
String sCalcScript = """
FIX ("FY17", $sPeriods)
ENDFIX
"""
// print to the job log
println sCalcScript
// return the generated calc script for execution
return sCalcScript
}else{
// if no cells edited print the log stating no cells edited
println "No cells edited to run the script"
}
Lets see what happens if the user edits the cell in the data form and tries to save, below is the screenshot of the log generated.
and if no cells are edited the logs show as
As you see it generates the script and includes only those members (cells) which are edited.
Another reason to love Groovy :)
Cheers --
Happy new year 2018 to all the readers. May you all have a great year ahead.
Today we will see how groovy can be used to generate script to calculated only on the edited cells (not to be confused with intelligent calculation).
Below is the snippet of the code.
//Get current Data Form
DataGrid curGrid = operation.getGrid()
// Holds the value for the venders that have changed
Set<String> periodList = []
// Iterater which gives you only the edited cells
curGrid.dataCellIterator({DataCell cell -> cell.edited}).each { DataCell cell ->
periodList << cell.getMemberName("Period")
}
// Holds the list of members from the POV – the function returns an array, so this
// parsed the array and places quotes around each member and separates them with a comma
// if cells are edited only then execute the script
if (periodList) {
// convert the list to comma separated value (ex,. if sep, oct and nov are edited the sPeriods will hold value as Sep, Oct, Nov)
String sPeriods = """ "${periodList.join('","')}" """
// Generate the script and assign it to String variable as below
// $ needs to be prefix for variable as show for $sPeriods which will be replaced with Sep, Oct, Nov
String sCalcScript = """
FIX ("FY17", $sPeriods)
ENDFIX
"""
// print to the job log
println sCalcScript
// return the generated calc script for execution
return sCalcScript
}else{
// if no cells edited print the log stating no cells edited
println "No cells edited to run the script"
}
Lets see what happens if the user edits the cell in the data form and tries to save, below is the screenshot of the log generated.
and if no cells are edited the logs show as
As you see it generates the script and includes only those members (cells) which are edited.
Another reason to love Groovy :)
Cheers --
Comments
Post a Comment