Anywhere API Reference – ModelData

Main page of the Anywhere API Reference

The ModelData class represents a record stored in the app cache. The ModelData class provides useful method to get and set fields of the record.

See also ModelDataSet.

set(attributeName, value)

Sets the value of the attribute.

Parameters

  • attributeName – Name of the attribute to be set.
  • value – The value to be set.

setDateValue(attributeName, dateValue)

Sets the value of the date attribute.

Parameters

  • attributeName – Name of the attribute to be set.
  • dateValue – A Date object. A null value can also be passed.

Examples

wo.setDateValue('changestatusdate', this.application.getCurrentDateTime());
meter.setDateValue('lastreadingdate', assetmeter.getAsDateOrNull('lastreadingdate'));
crew.setDateValue("startdate", DateTimeUtil.fromDateTimeToDate(currentDateTime));

setNullValue(attributeName)

Sets the value of the attribute to ‘null’.

Parameters

  • attributeName – Name of the attribute to be set.

Examples

resetTimer: function(woTimer) {
  woTimer.setNullValue("wonum");
  woTimer.setNullValue("startTime");
  woTimer.setNullValue("endTime");
  woTimer.setNullValue("duration");
  woTimer.setNullValue("workOrderId");
},

get(attributeName)

Retrieves the current value of the specified attribute.

Parameters

attributeName – Name of the attribute to be retrieved.

Examples

var hours = crew.get('regularhours');

getAsDateOrNull(attributeName)

Retrieves the current value of the specified attribute as a Date.

Examples

var starttime = woTimer.getAsDateOrNull("startTime");

isNull(attributeName)

Determines if the value of the passed attribute is null.

getPendingOrOriginalValue(attributeName)

Retrieves the updated value of the specified attribute.

Examples

var currWo = eventContext.getCurrentRecord();
var desc = currWo.get("description");
var descNew = currWo.getPendingOrOriginalValue("description");

Logger.trace("[AD] Old description " + desc);
Logger.trace("[AD] New description " + descNew);

setPendingValue(attributeName, value)

Updates the value of the specified attribute.

Parameters

attributeName – Name of the attribute to be set. value – Value be set.

Examples

var currWo = eventContext.getCurrentRecord();
var desc = currWo.get("description");
var descNew = currWo.getPendingOrOriginalValue("description");

if(descNew != descNew.toUpperCase()) {
  currWo.clearPendingValue("description");
  currWo.setPendingValue("description", desc.toUpperCase()));

clearPendingValue(attributeName)

Undo any change of the value of the specified attribute.

clearAllPendingValues()

Undo any modified attribute.

getOwner()

Returns the ModelDataSet that contains this record.

Examples

var woSet = currentWo.getOwner();

In this example the getOwner() method is used to get the owner set and save changes.

ModelService.saveAll([workOrderSet,
currWo.getOwner()]).then(function() {
  self.ui.hideCurrentView(PlatformConstants.CLEANUP);
}).otherwise(function(error) {
  self.application.showMessage("Error saving WO");
});

getLoadedModelDataSetOrNull(complexAttributeName)

Directly loads a complex attribute data from the JSON Store without storing it in the app cache. The getLoadedModelDataSetOrNull method basically looks at the attribute’s value and returns the associated ModelDataSet.

A reference to the ModelDataSet is not put in the app cache.  The calling code can add it using Application.addResource() method.

Parameters

  • complexAttributeName

Examples

var taskSet = workOrder.getLoadedModelDataSetOrNull("tasklist");

getRuntimeFieldMetadata(fieldName)

Returns field metadata.

Metadata can be used to set required or read-only fields.

Parameters

  • fieldName

Examples

var rotassetmetadata = creatingMaterialItem.getRuntimeFieldMetadata('rotassetnum');

rotassetmetadata.set('required', false);
rotassetmetadata.set('readonly', false);

isNew()

Determines is the record has been added to the data set and not yet saved.

Examples

if (!workOrder.isNew()) {
  ModelService.save(workOrderSet);
}
this.ui.hideCurrentView();

deleteLocal()

Deletes the local resource to discard any unsaved change.

Examples

if(currWO && currWO.isNew() && currWO.get('wonum') == null) {
  currWO.deleteLocal();
}

getModelDataSet(complexAttributeName, [useExisting])

If the ModelData comes from the server and can be saved, this method will always return a new ModelDataSet unless useExisting is true.

Parameters

  • complexAttributeName –
  • useExisting (optional) –

Examples

var actuallaborlistPromise = curCrew.getModelDataSet('crewlabor');
var currWo = eventContext.getCurrentRecord();
currWo.getModelDataSet('assetlocmeterlist').then(function(multiAssetLocSet) {
  wo.assetlocmeterlist = multiAssetLocSet;
});

Scroll to top