Share via


Forms Script Examples

This section shows examples of scripts you might write in your Forms tools.

Displaying a Message in the Status Bar

The following code demonstrates how you can display a message in the status bar. It does not specify an icon, so it contains a 0 as the second parameter.

var app=GetApp();
app.DisplayStatusBarMessage("your message goes here",0);

Displaying a Dialog Box

The following code demonstrates how to display a dialog box and test whether the user has clicked OK or Cancel.

var app=GetApp();
var UserText= app.DisplayTextInputDialog(
  "Continue to process form?", "Test Dialog");
if (UserText.Result == GrooveDialogBoxResultCode_OK)
{
  // user entered data, available in UserText.Data
}
else
{
  // user cancelled
}

Enumerating Members

The following code gets the enumeration for the Member Names and the enumeration that contains both the Member Names and Member URLs.

var app=GetApp();
var MemberNameEnum= app.CreateMemberNameEnum();
while (MemberNameEnum.HasMore())
{
  var MemberName = MemberNameEnum.OpenNext();
  // do something with Member Name
}
var MemberNameURLEnum= app.CreateMemberNameURLEnum();
while (MemberNameURLEnum.HasMore())
{
  var MemberNameURLPair = MemberNameURLEnum.OpenNextPair();
  var MemberName = MemberNameURLPair.First;
  var MemberURL = MemberNameURLPair.Second;
  // Have both member's name and URL
  if (MemberURL != app.CurrentAuthorURL)
  {
    // this member is not the current user
  }
}

Sending an Instant Message

The following code sends an instant message to all members of the space except the current author when the user clicks on a button.

function SendIMButton_OnClick(i_objInput)
{
  try
  {
    var app=GetApp();

    // Put up Dialog message
    var userText = app.DisplayTextInputDialog("Message text",
    "Send instant message to other workspace members with link to this record");

    if (userText.Result == GrooveDialogBoxResultCode_OK)
    {
      // send message
        var URLArray = new Array();
        var index=0;
        var MemberNameURLEnum= app.CreateMemberNameURLEnum();
      while (MemberNameURLEnum.HasMore())
      {
        var MemberNameURLPair = MemberNameURLEnum.OpenNextPair();
        if (MemberNameURLPair.Second != app.CurrentAuthorURL)
        {
          // if not current user, add URL to array
          URLArray[index++]=MemberNameURLPair.second;
        }
      }
      var URLEnum = CreateBSTREnumFromArray(URLArray)
      app.SendInstantMessage(URLEnum, userText.Data, true, true);
    }
    // if not = 1, user clicked cancel; do nothing    

  }
  catch (error)
  {
    GetApp().DisplayError("An error has occurred: " + error.description
    + "[" + error.number + "]");
  }
}

See Also

Concepts

Using Scripts in the Groove Forms Tool