XDocument.View workaround in OnLoad eventhandler?

J

John

In my OnAfterChange eventhandler I use the following code and it works just
fine:
thisXDocument.View.ExecuteAction("xCollection::insert", "group_1");

Now, I know that the above code will not work in the OnLoad eventhandler.
Does anyone have a workaround for using the above code during the OnLoad,
though? I really need to insert sections dynamically based on current table
data as soon as the user opens up the form.

Any help is appreciated. Thanks.
 
P

Perry Faulkner

Hi John,

It's a dreadful workaround, but what can you do when the
tool is missing the necessary pieces? This is what I do
for after load, but before user gets the form:

In the onLoad, create an error, e.g.

XDocument.Errors.Add(myfield, "SomeError", "add grp", "",
100, "modeless");

You'll have to play with the exact parameters to suit
yourself. myfields is the root node for the form xml,
i.e. something like:

myfield = XDocument.COM.selectSingleNode("/my:myFields");

as the error needs to be associated with some node, and
the top sounds good. You might want to use the node that
your adding to, instead!

Then in your taskpane, add an init handler and put code
there to loop through the errors and do the add when the
error exists. This assumes your onload actions may vary
based on some condition. If you are always going to do
this action, then just put it into the taskpane onload
handler and forget about the error. I use the error to
pass load success/fail state between the form onload and
the taskpane onload.

If there are multiple conditions, just add multiple
errors, with different codes, etc. then test for each and
carry out the necessary action! The error check code
would be something like:

var item = 0;
while (i < gXDoc.Errors.Count() {
var err = gXDoc.Errors.Item(i);
if (err.Type=='USER_SPECIFIED' && err.ErrorCode==100) {
// do something here now we've found the error

// remove the error - its only an event mechanism
gXDoc.Errors.Delete(err.node, err.ConditionName);
} else i++;
}

You ALWAYS have a taskpane (view), but you may not have a
taskpane.html, if not (I'm not sure if it's created with
a new form), create one, add it to the form resources and
setup the onInit, as you would with a regular
html/javascript combination. Then put your code there,
for example:

<html>
<script>
var gXDoc = window.external.XDocument;
function init() { // do add repeat }
</script>
<body onLoad="init()">
Just some explanatory text about the form
</body>
</html>

The taskpane onload always gets invoked after load, but
has the advantage of being able to access the XDocument.

This isn't a perfect situation, but its been working for
me!

HTH
Perry
-----Original Message-----
In my OnAfterChange eventhandler I use the following code and it works just
fine:
thisXDocument.View.ExecuteAction
("xCollection::insert", "group_1");
 
M

Matthew Blain \(Serriform\)

That's an unusual way to pass data between the document and the task pane.
You could also use Named Node Properties for this purpose, or a variable in
your script/code, or a secondary DOM.

However, for this task it's entirely unnecessary. The reason you cannot use
ExecuteAction here is because it works on the view, not the data (strange
design, but that's the way it is), and there is no view in the OnLoad event.

Two alternate ways to do it:
1) Add XML OnLoad using DOM calls.
2) Handle the OnSwitchView event. Set a variable in your code to say "still
loading", then in the first OnSwitchView event, check the flag, and if it's
true do the initial view-specific setup and clear the flag.

--Matthew Blain
http://tips.serriform.com/
http://www.microsoft.com/MSPress/books/7128.asp
 
J

John

Thanks Perry and Matthew for all the help.

Matthew Blain (Serriform) said:
That's an unusual way to pass data between the document and the task pane.
You could also use Named Node Properties for this purpose, or a variable in
your script/code, or a secondary DOM.

However, for this task it's entirely unnecessary. The reason you cannot use
ExecuteAction here is because it works on the view, not the data (strange
design, but that's the way it is), and there is no view in the OnLoad event.

Two alternate ways to do it:
1) Add XML OnLoad using DOM calls.
2) Handle the OnSwitchView event. Set a variable in your code to say "still
loading", then in the first OnSwitchView event, check the flag, and if it's
true do the initial view-specific setup and clear the flag.

--Matthew Blain
http://tips.serriform.com/
http://www.microsoft.com/MSPress/books/7128.asp
 

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