cancel
Showing results for 
Search instead for 
Did you mean: 

Working with Object Tables in SAP Mobile Development Kit

Will3
Explorer
0 Kudos

Hi All!
I am having trouble understanding, and gaining access to the values within object tables. My current project uses a 'checklist' which uses the object table as its main component, and each 'item' in the checklist has a boolean field in its ODATA called 'isMandatory'.
Ultimately, I need to be able to submit this checklist using a submit button at the bottom of the page, ONLY IF all items that are Mandatory have been populated. I just have no idea how to access those values...

I have attached a text file with the page structure taken. Currently, the 'isMandatory' value is being held in the statusText field.

Any help would be greatly appreciated!

Accepted Solutions (0)

Answers (2)

Answers (2)

bill_froelich
Product and Topic Expert
Product and Topic Expert

I don't see the StatusText in the Object Table as being set.  However the Object Table is a display control.  There is no way to access it's content (plus it pages data in so there is no guarantee all the data is loaded in the control yet).  If you need to validate that all items with isMandatory are populated correctly you can use a rule and perform a clientAPI.read to target the same entity set as the Object Table and include isMandatory eq true in the filter criteria.  Then loop over the results to confirm the necessary fields are populated before proceeding with the submission process.

Will3
Explorer
0 Kudos
Thank you! I don't have much experience looping through object tables, to be honest I don't even know how to 'view' the structures in the MDK debugger in order to script a loop. Are there any tools/blogs or simple script/rule examples of what an object-table looping script might look like?
bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Here is an example of calling read with a filter and looping over the results.

export default function ValidateItems(context) {
    let pageProxy = context.getPageProxy();
    let clientData = pageProxy.getClientData();
    var valid = true;
    return context.read('/MDKApp/Services/Sample.service', 'MyEntitySet', [], `$filter=isMandatory eq 'X'`).then((results) => {
        if (results) {
            for (let i = 0; i < results.length; i++) {
                let item = results.getItem(i);
                // Validate item properties are set, can do as a single check or by muiltiple checks on the item
                if (item.prop1 && item.prop2) {
                    valid = true;
                } else {
                    valid = false;
                    // Display an error message? and quit loop?
                }
            }
            return valid;
        }
    });
}

The example is for the validation check is just a simple check.  You can expand that based on your requirements and decide what you want to do when a validation failure occurs.