4

I'm looking to implement a custom chart in Maximo that pulls Asset mbo values and populates a chart that is visible on the Assets application. Like so: Graph in Assets application

I can successfully render a chart and pull data from a hardcoded Asset Mbo, but I can't figure out how make the chart dynamic for an individual Asset. E.g Asset AB100001 is selected from the list tab, but Asset AB234560 is hardcoded into the jsp code, so data from Asset AB234560 will be rendered on every chart, for every asset.

My jsp code looks something like this example, where this developer is getting meter data and displaying it on the same type of jsp chart:

<%@ include file="../common/componentheader.jsp"%>  
<%
String width = component.getProperty("width");
String height = component.getProperty("height");
String assetnum = boundComponent.getString();

MboSetRemote readingsSet = s.getMboSet("MEASUREMENT"); 
readingsSet.setWhere("ASSETNUM = '11450' and METERNAME = 'O-PRESSUR'");
readingsSet.reset();
String readingData = "[";
for (MboRemote r = readingsSet.moveFirst(); r != null; r = readingsSet.moveNext())
{
    readingData += "{'Offset_ms':" + r.getDate("MeasureDate").getTime() + 
                    ",'Value':" + r.getDouble("MeasurementValue") + "},"; 
};
readingData += "]";
%>

This is almost exact what I need, except you'll notice that he hardcodes the assetnum when using the setWhere in line 3: readingsSet.setWhere("ASSETNUM = '11450' and METERNAME = 'O-PRESSUR'");

Is there a way to use a binding variable in the setWhere function to dynamically pull the assetnum, instead of using the string '11450'?

Link to a blog post with this situation: http://vietmaximo.blogspot.com/2018/03/maximo-custom-control-part-iv-create.html

ChrisAngj
  • 305
  • 3
  • 11
  • I like this question. – User1974 Nov 17 '19 at 07:47
  • There should be a `getApp()` method, or something, on `component` that will return a handle to the current App. I think on the App there's a `getMboSet()` method that takes no arguments, because it returns the MboSet the App is working with. I'd have to spend some time with Maximo's JavaDocs or JD GUI to piece together the chain of calls, but I'm sure it can be done. And then, of course, you should use `psdi.mbo.SqlFormat` instead of just concatenating the number into the where clause. – Preacher Nov 18 '19 at 17:08
  • I'll leave my previous comment for what value others may get in deciding how to start looking for help. However, I have now seen that assetnum is already available in the code you posted, and so have offered an Answer. – Preacher Nov 18 '19 at 19:36

1 Answers1

1

Near the beginning, we see this line:

String assetnum = boundComponent.getString();

OP said that boundComponent.getString(); was returning Undefined. Some research has shown that this code should work better:

String assetnum = boundComponent.getDataBean().getMbo().getString("ASSETNUM");

then this line

readingsSet.setWhere("ASSETNUM = '11450' and METERNAME = 'O-PRESSUR'");

should become something like this

SqlFormat readingWhere = new SqlFormat("ASSETNUM = :1 and METERNAME = 'O-PRESSUR'");
readingWhere.setObject(1, "ASSET", "ASSETNUM", assetnum);
readingSet.setWhere(readingWhere.format())
Preacher
  • 2,127
  • 1
  • 11
  • 25
  • ASSET is a site-level object, so ASSETNUM may exist for multiple sites, so you really need to improve the code to account for that. And while you're at it, you should see if you can pull in the meter name dynamically, too. You might need to put your chart under or in the expanded table of Meters. – Preacher Nov 18 '19 at 19:38
  • In this context, what does the boundComponent keyword do? I couldn't find much documentation on it. After a little debugging, I realized that line was printing 'Invalid Binding' so I don't have the assetnum I need. – ChrisAngj Nov 18 '19 at 20:50
  • That, I don't know. If I was you, I would look in the included `componentheader.jsp` to try to figure that out. I was just trusting the code did what it appeared to do. – Preacher Nov 18 '19 at 23:31
  • I needed to do a bit more research on this for my own reasons. I have updated the answer to include code that should work to set `assetnum`. – Preacher Nov 19 '19 at 15:57