I want to display messages generated by a business rule in the import log

chanken
Tera Contributor

Hi Everyone,

I want to display messages generated by a business rule in the import log.

I check the correlation of fields with business rules. If an error occurs, a message is displayed. This error may also occur when running the import set. I want to display a message in the import log when an error occurs in the execution of the import set. In this case, do I have to implement the same check as the business rule in the transform map?

regards.

3 REPLIES 3

Jon Barnes
Kilo Sage

I have used this method in some custom portal widgets to capture business rule error messages that were triggered using gs.addErrorMessage() and it worked like a charm. You could tweak this to get Info Messages as well.



since this is being done via an import, not sure if gs.getErrorMessages() will return anything, but worth trying.



Once you have the messages array in msgs, you can format as a string and write to the logs. flush messages is used so that you don't get the same messages over an over again.



var msgs = gs.getErrorMessages().toArray();


if (msgs.length > 0) {


  msg = msgs[0] + '';


  gs.flushMessages();


}



Also, this doesn't work in a scoped app.


Hi Jon,



Thank you for your solution.


I tried it.


However, an error occurred.



----------------------------------------------------------------------------------------------------------------------------------------------------


Java.lang.SecurityException: Method returned an object of type ArrayList which is not allowed in scope aaa


Caused by error in sys_transform_script.0945a89fdbcc97404b855fa0cf9619ba.script at line 1



==> 1: (function runTransformScript(source, map, log, target /*undefined onStart*/ ) {


2:


3:   var msgs = gs.getErrorMessages().toArray();


----------------------------------------------------------------------------------------------------------------------------------------------------



I do not seem to be able to use ArrayList because my application scope is not global.


How do I solve it?


Unfortunately, it doesn't work in scope. I tried in Istanbul and it doesn't work in scope. but in Kingston, it does seem to work in scope, but it returns an array instead of an ArrayList.



One possible solution is to put it in a global script include and allowing your scoped app to call the script include. Make sure the new script include is available to all application scopes.



var MySessionUtil = Class.create();



/*


This function will return any session error messages that may have happened during an update


that weren't captured because they were in a BR


*/


MySessionUtil.getSessionError = function() {


  var msg = null;


  var msgs = gs.getErrorMessages().toArray();


  if (msgs.length > 0) {


      msg = msgs[0] + '';


      gs.flushMessages();


  }


  return msg;


};



then, within your scoped app, call it as global.MySessionUtil.getSessionError(). this should return a string or null if there are no messages.