Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

Table of Contents

Sort a List

Description:

Sorts the content of the item that is passed to the function.  The function supports Dropdown, Select One and Select Many.  The function will overwrite the options of the item that is passed to it.  If the item has a selected value then that value will still be selected after the list is sorted.

...

Code Block
languagejs
var srv = form.getServiceConfiguration('SC_theService');
srv.connectEvent("onCallFinished", function(success)
{
  if(success) {
   //change the F_DropDown to the ID of the object that you want to sort
  app.getSharedData().sortList(form.getPage('P_NewPage').F_DropDown, "title");
  }
});

Function:
app.getSharedData().sortList = function(theItem)
{
//theItem - The UI object for the list item
//sortBy - Valid values are "title" or "value"
app.getSharedData().sortList = function(theItem,sortBy)
{
    if(typeof theItem === "undefined") {
      return;
    }

    if(sortBy === null) {
      sortBy = "title";
    }

    //store the current value
    var value = theItem.getBOAttr().getValue();

     //sort the list
     var options = theItem.getOptions();

     if(options !== null) {
       options.sort(function(a,b) {
         return get(a, 'title'sortBy).localeCompare(get(b, 'title'sortBy));
       });
       theItem.setOptions(options);

       //reset back to the current value
       theItem.getBOAttr().getValue(value);
     }
}

Remove Duplicates From List

Description:
This function will remove any duplicate options found the current set of options.

...

Code Block
languagejs
app.getSharedData().removeDuplicatesFromList = function(theList) {
    var newList = new Array();

    //loop through the current list
  for(var j=0; j<theList.length;j++) {
      var curItem = get(theList, j);
      var itemFound = false;

      //loop through the newList checking to see if the item is there
      for(var k=0; k<newList.length;k++) {
        if(get(curItem, 'title') === get(get(newList, k), 'title')) {
         itemFound = true;
        break;
        }
      }
      if(!itemFound) {
          newList.push(curItem);
      }
  }
  return newList;
}

Remove Blank Options From List 

Description:

Returns a new List that does not contain the blank value.  Supports Select One, Select Many and Dropdown objects.

...

Code Block
languagejs
// theList - the List item from which to remove blank options
app.getSharedData().removeBlankFromList = function(theList) {
  //check all options for a blank value and remove it...
  var newList = new Array();
  //loop through the current list
  for(var j=0; j<theList.length;j++) {
      var curItem = get(theList, j);
      if(curItem !== "") {
          newList.push(curItem);
      }
  }
  return newList;
}

Randomize List Choices

Usage:

1. Copy the function in to the Application...onStart event.

...

Code Block
languagejs
// Returns a random number between the numbers specified. */
app.getSharedData().randomFromInterval = function(from,to) {
return Math.floor(Math.random()*(to-from+1)+from);
}

// Randomizes the selections of the specified list item.
app.getSharedData().randomList = function(theItem) {
//store the current value
var value = theItem.getBOAttr().getValue();

//set up the arrays
var arrOptions = theItem.getOptions();
var tmpOptions = theItem.getOptions();
var newOptions = new Array();

//Randomise the list
if(arrOptions !== null) {
for ( var i = 0; i < arrOptions.length; i++ ) {
//the random number should be between 0 and the length of the array
var j = app.getSharedData().randomFromInterval(0,tmpOptions.length-1);
var temp = get(tmpOptions, j);

//assign the item to the new array
newOptions.push(temp);

//remove the item from the temp array
tmpOptions.splice(j, 1);
}

//Set the options back
theItem.setOptions(newOptions);
//reset back to the current value
theItem.getBOAttr().getValue(value);
}
}

Get Dropdown Title

Description:

When you are using an ID for the saved value of a drop down and you need to get at the actual title.

...

Code Block
languagejs
// theItem - the UI object of the item to validate
// theLength - the max length of the field, if exceeded the field will be set to invalid
// theMsg - The text to render if the length is exceeded.
app.getSharedData().fieldLengthValidation = function (theItem, theLength, theMsg) {
  var dval = theItem.getDisplayValue();

  if(dval.length > theLength) {
    theItem.getBOAttr().setValid(false, theMsg);
  } else {
    theItem.getBOAttr().setValid(true, '');
  }

Remove Item From List

Descripton:

Removes the blank option from the list even if it is not the first, will also remove any duplicate blank options.

Function:

Code Block
languagejs
//   theList - the List item from which to remove blank options
app.getSharedData().removeItemFromList = function(theList, theVal) {

  //check all options for a blank value and remove it...
  var newList = new Array();

  //loop through the current list
  for(var j=0; j<theList.length;j++) {
debugger;
      var curItem = get(theList, j);
      if(get(curItem, 'title') !== theVal) {        
        newList.push(curItem);        
      }      
  }
  return newList;
}
}

Remove Items From List

Description:

Removes the options from the list that are found in the omitNames data passed to it.

...

Code Block
// theList - the List item from which to remove blank options
// omitNames - string of items to omit from the list
app.getSharedData().removeItemsFromList = function(theList, omitNames) {

  //check all options for a blank value and remove it...
  var newList = new Array();

  //loop through the current list
  for(var j=0; j<theList.length;j++) {
debugger;
      var curItem = get(theList, j);
     
      if(typeof omitNames !== "undefined" && omitNames.indexOf(get(curItem, 'title')) === -1) {
        newList.push(curItem);
      }
           
  }
  return newList;
}

Get Checklist Title

Description:

Returns the displayed title of the checklist selection.  You pass it the value.

...