View.ExecuteAction Method

InfoPath Developer Reference

Executes a Microsoft Office InfoPath 2007 editing command against a form's underlying XML document, based on the data selected in the view that is associated with the View object.

Version Information
 Version Added:  InfoPath 2003

Syntax

expression.ExecuteAction(bstrAction, varXmlToEdit)

expression   An expression that returns a View object.

Parameters

Name Required/Optional Data Type Description
bstrAction Required String The name of the editing action to perform.
varXmlToEdit Optional Variant The name of the field or group to which to apply the editing action. This is equivalent to the value of the name attribute in the xmlToEdit element of the form definition (.xsf) file.

Return Value
Nothing

Remarks

The ExecuteAction method is used to programmatically perform built-in InfoPath editing actions against a form's underlying XML document, based on the selected context in a view.

The action that is executed will be the same action that would be used when clicking on an equivalent menu or toolbar button; namely one for which the button element in the .xsf file has corresponding xmlToEdit and action attributes. As with using a button, the action will be based on current selection: it will act on the selected context (and in the case where the selection would lead the button to be disabled, then the ExecuteAction method will have no effect).

Note

It is possible with scripting code to first set the selection context by using the SelectNodes or SelectText methods of the View object, then calling the ExecuteAction method to act on that context.

The ExecuteAction method will return an error for the following reasons:

  • The bstrAction parameter does not contain a valid editing component name.
  • The varXmlToEdit parameter does not match an editing component that is defined in the view.
  • The varXmlToEdit parameter is required for a specific editing action.
  • The editing action is not applicable to the selected context.

Valid parameter combinations

The following is a table of parameter combinations that can be used with the ExecuteAction method.

Combination Description
"Copy" Copies the selected data to the clipboard.
"Paste" Copies data from the clipboard to the insertion point.
"Cut" Removes the selected data and copies it to the clipboard.
"Delete" Deletes the selected data.
"xCollection::insert", "xmlToEdit" Inserts data based on the selected context using the xCollection editing component. If current selection is within a container of the xCollection, specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is appended within that container.
"xCollection::insertBefore", "xmlToEdit" Inserts data before the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is inserted before that item.
"xCollection::insertAfter", "xmlToEdit" Inserts data after the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is inserted after that item.
"xCollection::remove", "xmlToEdit" Deletes data from the selected context using the xCollection editing component. If current selection is within an item of the xCollection, as specified by its xmlToEdit element in the .xsf, then that item is deleted.
"xCollection::removeAll", "xmlToEdit" Deletes all data contained within the selected context using the xCollection editing component. If current selection is within a container of the xCollection, as specified by the xmlToEdit element in the .xsf, then this action deletes all the items within that container.
"xReplace::replace", "xmlToEdit" Replaces the data in the selected context using the xReplace editing component. If current selection is within an item of the xReplace, as specified by its xmlToEdit element in the .xsf, then that item is replaced by the fragmentToInsert element data.
"xOptional::insert", "xmlToEdit" Inserts data based on the selected context using the xOptional editing component. If current selection is within an container of the xOptional, as specified by its xmlToEdit element in the .xsf, then the fragmentToInsert element data is appended within that container.
"xOptional::remove", "xmlToEdit" Deletes data from the selected context using the xOptional editing component. If current selection is within an item of the xOptional, as specified by its xmlToEdit element in the .xsf, then that item is deleted.

Note

In some cases, calling the ExecuteAction method from the OnClick event for a button in a view may cause an error. This is because the selected context changes to the button when the button is clicked. In this case, it is better to use a button (or link) on a custom task pane, toolbar, or menu to call the ExecuteAction method.

Security Level 2: Can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

Example

In the following example, the ExecuteAction method of the View object is used to delete selected data and place it on the clipboard:

JScript
  XDocument.View.ExecuteAction("Cut");

In the following example, the ExecuteAction method of the View object is used to insert data using the xCollection editing component, based on the selected context:

JScript
  XDocument.View.ExecuteAction("xCollection::insert", "group1_1");

See Also