0

This question probably is easy. I am trying to read a field of a IBM Maximo application and use this value in the method getList(). The value I want to use was not saved in the database yet.

Here is some pseudocode:

@Override
public MboSetRemote getList() throws MXException, RemoteException {
    MboSetRemote result = super.getList();

    //Here is where i dont know how to do it
    Date field = getFieldValue(FieldName) 

    //Here is where i want to use the value
    String string = "....field..." 
    result.setWhere(string);

    return result;
}

Thanks everyone, Regards

prieser
  • 55
  • 10

1 Answers1

0

I think the easiest and safest means to achieve your end of using the field value in your where clause is to use a bind variable, like this:

@Override
public MboSetRemote getList() throws MXException, RemoteException {
    MboSetRemote result = super.getList();

    //Here is where i want to use the value
    String string = "....:fieldName...";
    result.setWhere(string);

    return result;
}

Notice the colon on the front of :fieldName in string. When Maximo sees this, it will look (not case-sensitive) on the current record / Mbo for an attribute named fieldName and replace :fieldName with the value in the attribute -- wrapped in quotes or whatever, as applicable to the attribute's type (ALN, UPPER, DATE, etc).

This approach is better than the approach you presented because it will employ Maximo's framework to prevent SQL injection attacks and etc.

That said, the way to get the field value would be as follows:

Date fieldValue = getMboValue("FieldName").getDate();

Further, I strongly suggest you get yourself a copy of Maximo's JavaDocs. You can do that here.

Pramod Gharu
  • 1,105
  • 3
  • 9
  • 18
Preacher
  • 2,127
  • 1
  • 11
  • 25
  • I'll need more information that "I'm having an error" if I'm going to help more. – Preacher Dec 09 '15 at 18:11
  • Many thanks for your help guys!! :) I did as you suggested but I'm having an error. `com.ibm.db2.jcc.am.SqlDataException: The syntax of the string representation of a datetime value is incorrect.` Also when I do `String query = ":fieldName"; System.out.println(query);` nothing is printed in logs. – prieser Dec 09 '15 at 18:19
  • I am sorry @Preacher. I pressed ENTER before finish the comment. Thanks a lot for you support! – prieser Dec 09 '15 at 18:21
  • No worries. For the `..string representation...` bit, I would put the intended where clause in a relationship, put a field on screen that uses the relationship, turn up SQL debugging on the relationship's Child Object, and see what gets put in the logs. If you get the same error there, you may have grounds for a PMR. Or maybe your data is a string and you're trying to convert it to a date? – Preacher Dec 09 '15 at 18:26
  • Regarding your `System.out.println(query);`, such output will go to your WebSphere's SystemOut.log files, or the equivalent in WebLogic if you're using that. But, using this syntax for logging is bad form in Maximo. Instead, you should get a handle to the MBO's logger and call its `info()` or `debug()` or etc method, which will cause your messages to be logged where Maximo logs instead of to the JVM's console. Read the APIs for help getting the MBO's logger. – Preacher Dec 09 '15 at 18:31
  • Maybe this is a stupid question but when you said that I should use :fieldName you mean fieldName is the name of the attribute. RIght? For example ASSETNUM if I am trying to read a field from ASSETS app. – prieser Dec 09 '15 at 20:08
  • Yes. :fieldName could be :assetnum – Preacher Dec 09 '15 at 20:09
  • thanks for your help! I could not use the safest alternative (colons) so for the moment i will use the `getMboValue("FieldName")`. Thanks again! – prieser Dec 11 '15 at 12:38