Josh Goldman weighs in:

 

You can make it easier for Forms tool users by adding macros to your Forms tools that allow the user to perform bulk operations on a group of selected forms. In the Issue Tracking tool, there is a Status field on the Issue and Response forms. What if a user has 5 issues and has closed them all. If you add a macro to the tool, the user could update all five issues at one time.

 

The mechanics of creating macros is covered in http://msdn.microsoft.com/en-us/library/bb290772.aspx . So I’ll just cover the code.

 

Here is the body of the macro to update all selected records so that the status is set to “Closed”

 

  i_FormRecord.SetField("Status", “Closed”);

 

That’s it.  You’re done developing the macro.

 

But the users like this macro so much that they want to use it to set the status to values other than “Closed”. You’ll have to add a little more code to make this work.

 

You can get them to enter the status by calling the DisplayTextInputDialog method.

 

  var dialogResult = i_FormsToolUIDelegate.DisplayTextInputDialog(

    "Status",

    "Set status for selected records",

    "Closed"

  );

 

This sets the default value of the dialog box to “Closed”.

 

But macros get executed one time for each selected record. You don’t want them to enter the status separately for each record. That’s not much of a time saver. In order to do this, you’ll create a global variable that will let you check if they’ve already entered a status value.

 

To do this, select the “More Code” button and enter:

 

var newStatus = "";

var statusEntered = "";

 

 

This defines two global variables, whose values are preserved from one record to the next..

 

Now here’s the full body of the macro:

 

if (statusEntered == "")

{

  var dialogResult = i_FormsToolUIDelegate.DisplayTextInputDialog(

    "Status",

    "Set status for selected records",

    "Planning"

  );

  if (dialogResult.Result == GrooveDialogBoxResultCode_OK)

  {

     newStatus = dialogResult.Data;

     statusEntered = "true";

  }

  else

  {

     statusEntered = "false" ;

  }

}

if (statusEntered == "true" && i_FormRecord.HasField("Status"))

{

  i_FormRecord.SetField("Status", newStatus);

}

 

By checking If statusEntered is an empty string, you ensure that the dialog box is displayed only once.

 

If it is empty, you display the text input dialog and then check the result. If the user has clicked OK, then you’ll update the status of each record to the specified value (which is available in the dialogResult.Data field).

 

But you should also check that the selected record has a Status field. If you don’t check and the user calls the macro with a keyword record selected, you’ll get a script error.

 

You can also look at the Update assignments macro that is already defined in the Issue Tracking tool.

 

Remember that macros work with InfoPath Forms tools in exactly the same way that they work in Groove Forms tools.