Groovy - Message box / Prompt in (E)PBCS using Groovy
Hi,
In Hyperion Planning, if we wished to give out the error or message box to the user we used @RETURN in the calculation script.
How about if we wish to give out the error or message box to the user? Yes, we can use @RETURN function in Groovy by returning it as a Calculation script.
If we wish to write it in pure Groovy format we can achieve the same using the Groovy methods. Below is the sample code.
/*set the datagrid object to null*/
DataGrid getGrid = null
/*set the message to be prompted when the script is not executed via Data form*/
String msgisForm = "This rule has to be executed from form"
/*create the message map using messageBundle*/
def mbUs = messageBundle(["validation.isForm":msgisForm])
/*load the message map using messageBundleLoader*/
def mbl = messageBundleLoader(["en" : mbUs]);
/*check whether the script is executed through dataform*/
try{
/*get the current grid */
getGrid = operation.grid
}catch(BindingsMissingException){
/*if the script is not able to find the current grid it will come to catch block*/
/*send the message prompt to the user if the script is not executed from the data form*/
throwVetoException(mbl, "validation.isForm")
}
println("Script executed from dataform")
In Hyperion Planning, if we wished to give out the error or message box to the user we used @RETURN in the calculation script.
How about if we wish to give out the error or message box to the user? Yes, we can use @RETURN function in Groovy by returning it as a Calculation script.
If we wish to write it in pure Groovy format we can achieve the same using the Groovy methods. Below is the sample code.
/*set the datagrid object to null*/
DataGrid getGrid = null
/*set the message to be prompted when the script is not executed via Data form*/
String msgisForm = "This rule has to be executed from form"
/*create the message map using messageBundle*/
def mbUs = messageBundle(["validation.isForm":msgisForm])
/*load the message map using messageBundleLoader*/
def mbl = messageBundleLoader(["en" : mbUs]);
/*check whether the script is executed through dataform*/
try{
/*get the current grid */
getGrid = operation.grid
}catch(BindingsMissingException){
/*if the script is not able to find the current grid it will come to catch block*/
/*send the message prompt to the user if the script is not executed from the data form*/
throwVetoException(mbl, "validation.isForm")
}
println("Script executed from dataform")
The script above is a demonstration of two thing, 1. Message box / Prompt to the user; 2 . Restrict the script execution to the data form
Hope you find it useful.
Thanks
Thanks for this post. Have a quick question:
ReplyDeleteprintln("Script executed from dataform") is not showing a message box upon save of form. I want to show messagebox to users upon save of form. Please could you help advise the right code. Thanks.
Hi,
Deleteprintln will show the message in the job console. If you wish to show the message box in the form you have to use the above code which is there in the post.
Basically this step will show the error prompt - "throwVetoException(mbl, "validation.isForm")" The setup is done above this code.
Remember one thing this stops the script execution, so probably you want it to place it at the bottom of the rule or at the last rule in case of ruleset.