Manipulate InfoPath elements using script

L

Levente Farkas

Hello,

I need to show/hide (insert/remove) an optional section
into an InfoPath form, based on some user action. I can
write an OnAfterChange event handler for, let's say a
checkbox, and in response to that I want to show/hide the
optional section. My take is this:

function msoxd_my_ResourceAddMethod::OnAfterChange
(eventObj)
{
// Write code here to restore the global state.
if(eventObj.IsUndoRedo)
{
// An undo or redo operation has occurred and the
DOM is read-only.
return;
}

// A field change has occurred and the DOM is
writable.
// Write code here to respond to the changes.
var dom = eventObj.XDocument.DOM;
var view = eventObj.XDocument.View;

if(eventObj.NewValue == "DynamicScan")
view.ExecuteAction
("xOptional::remove","group8_19");
else
view.ExecuteAction
("xOptional::insert","group8_19");
}

But the above code only works the first time (when the
optional section is not yet inserted), and successfully
inserts the section. After that, attempt (from script) to
either remove (if I manually insert the section on the
form) or reinsert gives me the following error:

"The specified bstrAction value for the View.ExecuteAction
call is not applicable for the current selection"

Anyone has experience with this? Any hints?

Best regards,
Levente
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top