UI5 – Dynamically call ValueHelpRequest functionality

Home / Blog / UI5 – Dynamically call ValueHelpRequest functionality

As promised, this is a continuation of yesterday’s post.  So to recap, I was able to use the code from SAP to recreate their example, and convert it to use my service.  This was the first hurdle, but certainly not the biggest.  Now that it worked in a very simple, static way, I needed to add it to my dynamic application.  By that I mean, my input fields are all created in the controller based on a custom table.  The table defines the fields to add on the fly.  This means that assigning the valueHelpRequest needed to be just as dynamic.  Here were the gotchas:

  1.  calling the method to call the valuehelprequest had to be done in-line.  Because the method for valueHelpRequest happens during the creation of the element, the input field doesn’t “technically” exist as it is being called.  So I needed to write this method as a function within the creation of the MultiInput element.  See below for a code example:

***********************************************************************************************

var that = this;
oLayout.addContent(new sap.m.MultiInput({
maxLength: 20,
enableMultiLineMode: true,
valueHelpRequest: function(evt) {
var sSearch, sDesc;
var sField = evt.getSource().getId();
this.theTokenInput = sap.ui.getCore().byId(sField);
this.theTokenInput.setEnableMultiLineMode( sap.ui.Device.system.phone);
this.aKeys= [“Key”, “Desc”];
// this.theTokenInput.setTokens(this.aTokens);
var oConfig = sap.ui.getCore().getModel(“config”).getProperty(“/results”);
for (var j = 0; j < oModel.length; j++) {
if (oModel[j].Field === sField) {
sSearch = oModel[j].SearchHelp;
sDesc = oModel[j].Descr;
}
}
this.aItems = sap.ui.getCore().getModel(sSearch).getProperty(“/results”);

sap.ui.controller(“ProxProdSup.view.Settings”).onValueHelpRequest(this.theTokenInput, this.aKeys, this.aItems, sDesc);
},
id: oModel[i].Field,
})
);

**********************************************************************************************

please note, in my example above, I have a model with the field name, description and the help service to call..  Also, this all occurs within the Settings view.  I still need to make some small adjustments to allow this to happen in any of my views.

the method onValueHelpRequest was my next obstacle, but relatively easy once I figured out what each piece of the code was doing.  Most of it was copied directly from the UI5 example (see yesterday’s post if you can’t find it yourself).  Minor tweaks, but nearly all of the code is the same except for hardcoded values (like company code are changed to variables).

So far so good…  I know had a working and dynamic search help.  However, it still didn’t do much.  I needed to update my filter code to interpret these new things called tokens (which lead to some strange dumps and a few infinite loops along the way…)  I’ll talk about those next week.

Thanks for reading,

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *