Anywhere API Reference - ModelDataSet

Main page of the Anywhere API Reference

The ModelDataSet class represents a data set in Maximo Anywhere. It is a collection of ModelData objects which hold data stored in the app cache. The ModelDataSet class provides useful method to iterate, filter, and manipulate data.
ModelDataSet objects are typically accessed using Application.getResource method. See the following example.
var woSet = eventContext.application.getResource("workOrder");
for(var i=0; i<woSet.count(); i++) {
  var wo = woSet.getRecordAt(i);
  // do something
}


find(queryAsString, listOfParameters)

Finds the data set with the query provided. This method does not change the state of the data set.

Parameters

  • queryAsString - The query to be applied to all records in the data set. Can be any expression valid for a javascript "if" statement, considering records attributes as variable names. This also can contain $1-$9 placeholders that refers to subsequent Arguments passed to the function.
  • listOfParameters - 0-9 Arguments to be replaced in the query for the corresponding $1-$9 placeholders.

Examples

dataSet.find("woNum == '1002'")
dataSet.find("woNum == '1002' || status == 'COMP'")
dataSet.find("priority <= 1 || creationDate > $1", new Date())
var asset = assetSet.find('assetnum == $1 && siteid == $2', assetnum, siteid);
if (asset.length == 0) {
  throw new PlatformRuntimeException("rotatingAssetNotThere", [assetnum]);
}
var itemnum = asset[0].get('itemnum');


filter(queryAsString, listOfParameters)

Filters the data set with the query provided. This method changes the state of the data set.
See find method for details and examples.


sort(listOfFields)

Parameters

  • listOfFields – comma-separated list of fields to sort

Examples

woSpecSet.sort('displaysequence asc, workorderspecid asc');


clearFilterAndSort()

Remove current filter and sort.

Examples

if(resource.isFiltered()) {
  resource.clearFilterAndSort();
}


isFiltered()

Determines if the data set is filtered.

Examples

if(resource.isFiltered()) {
  resource.clearFilterAndSort();
}


count()

Returns the number of ModelData object stored in the app cache within the ModelDataSet. Data is loaded by pages so this count may differ from the sever count. Use getListCount() method to retrieve the total number of records.

Examples

var crewSet = CommonHandler._getAdditionalResource(eventContext, "laborcrew");
for(var i=0; i<crewSet.count(); i++)
{
  var crew = crewSet.getRecordAt(i);
  // do something
}

if(laborSet.count() == 0) {
  throw new PlatformRuntimeWarning('invalidLabor');
}


getListCount()

Returns the total number of records in the data set. It is not affected by the page size.


lastIndex()

Returns the last index of the data set. It is always equal to count() - 1.

Examples

this.setCurrentIndex(this.lastIndex());


getCurrentRecord()

Retrieves the current record in the data set.

Examples

var currWo = this.application.getResource("workOrder");
if(currWo.getCurrentRecord().get('wonum') == '') {
  this.ui.hideCurrentView();
  return;
}


getCurrentIndex()

Returns the current record index in the data set.

Examples

if (this.getResource().getCurrentIndex() < 0) {
  return;
}


getRecordAt(index)

Returns the record at the specified index position.

Examples

for(var i=0; i<crewlaborLocalSet.count(); i++) {
  var currLabor = crewlaborLocalSet.getRecordAt(i);
  // do something
}


hasNext() / hasPrevious()

Determines if there is a next/previous record in the data set.

Examples

if(this.hasNext()) {
  // do something
}


next() / previous()

Returns the next/previous record in the data set. Returns null if at the end/beginning of the data set.


setCurrentIndex

Sets the current position in the data set.

Examples

var materialSummary = eventContext.application.getResource("materialSummary");
if(materialSummary.data.length>0) {
  materialSummary.setCurrentIndex(0);
}


foreach(f)

Iterates through the data set.

Examples

var toolList = workOrder.getLoadedModelDataSetOrNull('toollist');
if(toolList &&
toolList.count()>0) {
  var taskStoreToolMap ={};
  toolList.foreach(function(tool) {
  var toolStore = tool.storeroom == null ? ' ' : tool.storeroom;
  ...
  }
}


createNewRecord()

Creates a new record in the data set and returns a reference to it.
It is typically associated to a setDefaultValues method to be invoked on the object.

Examples

var workLogSet = CommonHandler._getAdditionalResource(this, "workOrder.workloglist");
var newWorkLog = workLogSet.createNewRecord();
var myUser = UserManager.getCurrentUser();
newWorkLog.set("createby", myUser);


No comments:

Post a Comment