How to Change Expression in Report Cells using BO Java SDK

Problem

“I have nearly 500 reports, each report having logo on the right up corner in all tabs, in a cell having formula “boimg://logo.bmp” and read as image URL. Now i have come up with change in logo format. Now the same formula is to be changed to “boimg://logo.jpg””.

Code

private static int replaceExpression(DocumentInstance widoc, String from, String to) {
   ReportDictionary reportDictionary = widoc.getDictionary();
   ArrayList nodes = getListOfTreeNodes(widoc.getStructure(), false);
   int n = 0;
   for (TreeNode node : nodes) {
      if (node instanceof ReportCell) {
         ReportCell reportCell = (ReportCell)node;
         ReportExpression reportExpression = reportCell.getExpr();
         if (reportExpression instanceof FormulaExpression) {
            FormulaExpression formulaExpression = (FormulaExpression)reportExpression;
            if (formulaExpression.getValue().compareTo(from) == 0){
               FormulaExpression newFormulaExpression = reportDictionary.createFormula(to);
               reportCell.setExpr(newFormulaExpression);
               n += 1;
            }
         }
      }
   }
   widoc.applyFormat();
   return n;
}

public static ArrayList getListOfTreeNodes(TreeNode root, boolean onlyLeaves) {
   ArrayList nodes = new ArrayList();
   treeNodeTraversal(root, nodes, onlyLeaves);
   return nodes;
}

private static void treeNodeTraversal(TreeNode node, ArrayList nodes, boolean onlyLeaves) {
   if (!onlyLeaves || node.isLeaf()) {
      nodes.add(node);
   }
   for (int i = 0; i < node.getChildCount(); ++i) {
      treeNodeTraversal(node.getChildAt(i), nodes, onlyLeaves);
   }
}

Source

https://bukhantsov.org/tools/ReplaceInReportCell.java

6 thoughts on “How to Change Expression in Report Cells using BO Java SDK

  1. Sorin Dudui

    Does it work under 4.x.? I receive the error “This feature is not implemented. (Error: RWI 00013)” at webidoc.getStructure();

    Regards,
    Sorin

    Like

    Reply
    1. dmytro Post author

      I cannot say that 4.x is developer friendly…

      You cannot do that using 4.x public SDK. The only thing that works from Report Engine SDK is report running workflow.

      Like

      Reply
      1. Allen W

        Hmm, sounds like the 4.x SDK is much more limited that it’s predecessors – in what ways?

        Like

      2. dmytro Post author

        Sorry it was old comment. 4.1 SDK is very promising. But it is completely new and based on RESTful webservices. (I have not tried it yet though)

        Like

      3. Allen W

        No problem 🙂 – I’m just trying to figure out why going from 3.x to 4.1 is so problematic. I’m guessing part of it is that it looks like SAP changed their approach to implementing some features.

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s