Novell Cool Solutions: Tip\ By Rudy Duym

Posted: 5 Jul 2007

Problem#

A Forum reader recently asked:

"I have a workflow where a manager can select a user and the applications they have access to. (The applications are in a checkbox pick list from a global query on load.) On the approval form, I can display the values I want with entity key for DN expression lookup; but I am unable to figure out a few things past that.

  1. ) How do i automatically have the "chosen" applications from the request form to show up "checked" on the approval form?
  2. ) I know how to use the display expression to show the values I want, but I want to be able to set a different value (not the DN) on my entity action. Basically, I want to read my application object for the CN value and place that on my user object."

And here's the response from Rudy Duym ...

Solution - Preselect Pick List values#

You can use the field.select() or form.select() method : field.select(/*string? || array?*/ values)

This highlights the entered text if the control is a Text, DNMaker, DatePicker or TextArea control. For list or choice-based controls, this will select the choice(s) corresponding to the values parameter. If no values are passed in, the first field option will be selected.

Note: When an array of values is passed in only the first value will be considered. This will be without effect on disabled or invisible fields. This can also trigger the onchange event for the current field.

Examples:

field.select("a"); // select the option "a" in a StaticList
field.select(["choice1", "choice2"]); // preselects 2 choices in a PickList of MVCheckbox

Solution - Get CN values#

As to your second question, maybe you can use IDVault.get() to get the cn value either in the form or in one of the workflow mappings. For example:
/*array*/ IDVault.get(/*string?*/ fieldname, /*string*/ dn, /*string*/ entity_key, /*string*/ attribute_key)

This corresponds to the IDVault.get() function of the workflow script engine. It retrieves the value(s) of the attribute for the given entity. The result will be an array of values. If the "field" parameter is specified, the result of the query will be used to refresh the content of the field. If you specify a null value for the fieldname, it will be up to the form developer to use the result of the query.

The method returns an array with the data values. For example:

var s = IDVault.get(null, dn, "user", "LastName"); field.setValues(s[0]); // s[0] contains values for last name

Problem - Show and Hide Buttons#

A Forum reader recently asked:

"I need an information about the ECMA-Script. Can I (and how should I) show/hide an Action Button (for example Submit, Cancel,..) from ECMA-Script? Does such a method exist?"

Solution - Show and Hide Buttons#

from Rudy Duym ...
You can intercept the action that is behind the buttons, but you cannot show/hide buttons like you can with fields.

To intercept the action you do something like the following example. In this example, the submit action is intercepted and the form will be submitted only if the user replies yes:

form.interceptAction("SubmitAction", "around",
  function (invocation) {
    if (confirm( "Are you sure you want to submit ?")) {
      var result = invocation.proceed(); return result;
    }
  }
);
You can block the action when certain conditions are met, to block you do not call the invocation.proceed() function.

That said, you can of course do whatever you want from within Javascript (that is what the form script basically is, with some extra methods thrown into it) - you only have to know the ID of the HTML element on which to operate. But watch out: each command action is duplicated if you use the choice "both" (as opposed to top or bottom) for the action buttons.

Problem - Alert on Empty String from Query#

A Forum reader recently asked:

"On a event, I'm doing a query for a user object. If the query does not return an empty string, I want to put a form.alert. The query looks like this:

var v = IDVault.globalQuery("idesist", "QUser", {LOGINID:form.getValue("loginid")});

How do I check for the return to be non-empty and the user to get the function form alert?"

Solution#

from Rudy Duym ...

This expression:

var v = IDVault.globalQuery("idesist", "QUser", {LOGINID:form.getValue("loginid")});

returns an array with 2 entries, each being also an array of values. The result will also be stored in the field "idesist", which corresponds to the first parameter value.

The first entry on the array contains the dn values returned by the query. You get the first value of this array with a v[0][0]. You can also loop over the values, of course.

The second entry contains the cn part of the dn values returned by the query. You get the first value of this array with a v[1][0].

So if you want to test whether a non-empty value was returned, you can use something like this:

      var v = "";
      try {
        v = IDVault.globalQuery("idesist", "QUser", {LOGINID:form.getValue("loginid")});      
      } catch (e) {};
      if (v.length > 0 && v[0].length > 0 && v[0][0] != "") {
       // non empty result
     }
Note: As a field destination is specified, the result of the query will also be automatically stored in the field "idesist"!

More Information#

There might be more information for this subject on one of the following:

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-9) was last changed on 08-Dec-2011 13:55 by jim