Assistance Needed: Retrieving Database Values from Another Table via JavaScript

Hello,

I am working on an SBM application and need to retrieve data from another table (e.g., EXTERNAL_TABLE) using JavaScript within a different application. I’ve attempted several approaches but haven’t been able to achieve the desired result. Below are some of the methods I’ve tested:

  1. Using JSON API - GetItemsByItemID:

    • Successfully retrieved individual items, but could not filter based on custom fields like Field1 (which is a custom field that I added).
  2. Attempted GetItemsByListingReport with Runtime Parameters:

    • Used URL: servername/.../498
    • This retrieves multiple records but does not filter based on UniqueID as expected.
  3. Tried JSON API getitemsbyreportfilter:

    • Example 1: servername/.../tmtrack.dll
    • Example 2: servername/.../tmtrack.dll
    • Both attempts returned errors indicating the report filter could not be read by ID, name, or UUID, or failed to apply the intended filter.
  4. Direct API Calls to Filter by Field Values:

    • Tested various endpoint structures but encountered "Unknown Function" errors, making it difficult to proceed.

I’d appreciate any guidance or best practices for achieving this, specifically how to filter data retrieval via JavaScript using SBM’s API or other recommended approaches.

Thank you!

  • 0  

    The SBM documentation is pretty good on explaining these different calls to access the data.

    For example, the GetItemsByItemID returns items based on the Item ID as described. It doesn't filter on the fields.

    The GetItemsByListingReport returns a set of items based on the defined report, not a single item. When I use this call, I usually use the Report Reference Name as it is easier to find then the report id. If you want to retrieve a single item, use GetItem.

    For GetItemsByReportFilter, which may work in your scenario to filter based on Field1, requires that you have created the filter in SBM workspace or SBM Composer and deployed the application.

    If your goal is to return a list of items based on filtering via a field, I would use the GetItemsByListingReport. You can set up a query at runtime parameter and pass that in via the post data.

  • 0 in reply to   

    I have create a report already in my workspace the report id is 498 and there is a query parameter in the search filter but it didn't work



    I posted a screenshot to have the URLs in it

  • 0 in reply to 

    the URLs got hidden when I posted my reply here

  • 0   in reply to 

    Aah, that helps.

    If you use the report id instead of the reference name, then you must use the field id instead of the field name, e.g.:

    .../jsonapi/GetitemsByListingReport/498?hasruntimeparams=1&F5034=1222

    vs

    .../jsonapi/GetitemsByListingReport/USR_TABLENAME/REFERENCENAME?hasruntimeparams=1&F_TS_TRANSGUID=1222

  • 0 in reply to   

    I got the FieldID from the TS_FIELDS table, but it didn't work with or without the F letter, my field ID based in the TS_FIELDS table is 6447 :



    it didn't work and it retrieved all records regardless of whether the parameter is correct or not, it should return nothing if the parameters are not valid,  

  • 0   in reply to 

    Do you only have one item in the table? I see that the returned results were only 1.

    You can try the UUID of the report and the field name to see what returns:

    .../jsonapi/GetitemsByListingReport/D677....?hasruntimeparams=1&F_TS_TRANSGUID=1222

  • 0 in reply to   

    Yes it should return one result but I cant see the desired result in the response JSON, the report should return :

  • 0   in reply to 

    If your table has more than one record, but only one is being returned, then the filter is probably working. You can see the one result in your screenshot.

    Is the filter text that you are passing in correct if you are getting the wrong item back?

  • 0 in reply to   

    Thank you Michael for your time. Yes, the filter is working if pass a correct value for the filter then I get some items in the "items": [] in the response, and if I pass something wrong the "items": [] will be empty.

    an example of a returned result for a valid filter (I've changed some values for privacy purposes) :

    "items": [
            {
                "id": {
                    "id"12199,
                    "uuid""",
                    "itemIdPrefixed""131284",
                    "itemId""131284",
                    "url""http://our server name?IssuePage&RecordId=12199&Template=view&TableId=1235"
                },
                "fields": {
                    "ISSUETYPE": {
                        "id"0,
                        "name""(None)"
                    },
                    "TITLE": {
                        "value""private title"
                    },
                    "SUBMITTER": {
                        "id"0,
                        "name""(None)"
                    },
                    "SUBMITDATE": {
                        "svalue""10/16/2024 09:26:46 AM",
                        "value"1729092406
                    },
                    "ACTIVEINACTIVE": {
                        "id"0,
                        "name""Active"
                    },
                    "PROJECTID": {
                        "id"104,
                        "name""the name of the project"
                    },
                    "STATE": {
                        "value""private state"
                    },
                    "OWNER": {
                        "id"0,
                        "name""(None)"
                    },
                    "SECONDARYOWNER": {
                        "value": []
                    },
                    "LASTMODIFIEDDATE": {
                        "svalue""10/16/2024 09:27:45 AM",
                        "value"1729092465
                    },
                    "LASTMODIFIER": {
                        "id"7,
                        "name""WebServices"
                    }
                }
            }
        ]

     
    so the field 'Client Long Name' is not included in the response,  as I mentioned before the report on the UI shows :



    so I thought the same three fields would be retrieved in the JSON response.

    .

  • 0   in reply to 

    You would assume that, but SBM requires that you have manually specify the fields to return.

    You'll need to pass in the specific fields in the item options.