Defaulting Picklists in the SLX Mobile Client
Posted By: Alex.Cottner on October 1st, 2012 in General, Javascript, SLX Mobile
No Gravatar

I had a request that required me to default several picklist fields throughout the SLX Mobile client. Normally this would mean hard coding the fields to populate with a certain value. But I wanted the client to be able to manage their default picklists values by marking items as “Default” in the client, just like they always have. After looking at the picklist control I realized this was actually pretty simple to do. All I needed to do was add a couple methods to the picklist object to pull down and set the default values, then I could call this from the “applyContext” methods on the forms I wanted this on.

Here is the code that I added to the Picklist control.

getDefaultValue: function() {
if (!this.Picklist)
return;
var request = new Sage.SData.Client.SDataResourceCollectionRequest(App.getService())
.setResourceKind('PickListItems')
.setContractName('dynamic');
request.setQueryArgs({
where: 'PickList.PickListName eq "' + this.Picklist + '" and OrderSeq eq (PickList.DefaultIndex + 1)'
});
request.allowCacheUse = true;
request.read({
success: this.setDefaultValue,
failure: function (xhr, o) {
console.log('Unable to populate deafult picklist item.\n' + xhr);
},
scope: this
});
},

setDefaultValue: function(data) {
if (data.$resources.length < 1)
return;
// else set the default value
this.setValue(data.$resources[0][this.storageMode]);
this.setText(data.$resources[0]['Text']);
},


Leave a Reply