Set a Default Value Programmatically.

N

nick brandwood

Hi there,

I have a form with a field that concats lots of text together.

this field is contained within text boxes on three views of the form, and
each view needs a different function to make this concat.

I've tried using the famous 'fx' button however, this seems to set the
formula for the field, not the text-box, as such, when I change view and set
the formula for that view, it changes all three formulas.

So, I've tried to do this using script (the field is called "notes"):

public void OnSwitchView(DocEvent e)
{

// grab notes node
IXMLDOMNode nodeNote =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:richiesta/my:note")

// look which form we are on, and set the default value formula
switch (thisXDocument.View.Name.ToString()) {
case "ferie":
thisXDocument.UI.Alert("ferie");
// set string for default formula
strDefaultFormula="concat("hello","world")
break;
case "permesso":
thisXDocument.UI.Alert("permesso");
// set string for default formula
strDefaultFormula="concat("hello","world")
break;
case "malattia":
thisXDocument.UI.Alert("malattia");
// set string for default formula
strDefaultFormula="concat("hello","world")
break;

default:
thisXDocument.UI.Alert("case crashed out.");
break;
}
nodeNote.something.somethingelse= strDefaultFormula
}


I am having difficulty finding which property of nodeNote I need to change.
As there doens't seem to be any reference to this on the web, perhaps it
can't be changed, and in that case, how do I do such a thing?

thanks again,

nick
 
N

nick brandwood

hello greg,

thanks for your reply.

I think you've not understood my question.

I have a form with three views, each for a particular case of the form.

Within those three views is a textbox that must compile a phrase based on
the information compiled in the form. The phrase that is gramatically
different based on which view you are using. A user would not use all three
views, but would choose the view based on the requirements at the time.
(Sick, Approved Absence or Holiday)

As you state, the textbox is indeed linked to the data, not the view and as
such, even though a text box exists on three different views, it only has one
default value function.

I was looking for a method to change the default value function based on
which view is opened, thereby faking an equation for each view. As you can
see from the code below, however I couldn't find a property or method on the
node object that allows me to define the default value function.
nodeNote.something.somethingelse = strDefaultFormula

It it not possible to change this equation at run time?

I do not want to create three different text boxes, as data should be
contained within the same XML element.

thanks again for your quick reply...

nick
 
N

nick brandwood

....so the default value equation is set by giving as the value...?

ok, will give it a try.

thanks

Greg Collins said:
Okay... that being the case, I think you are doing the correct thing by using an OnSwitchView event handler. That is the only way to do what you want to do.

The assignment property you are looking for is ".text" or ".nodeValue":

nodeNote.text = strDefaultFormula

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



hello greg,

thanks for your reply.

I think you've not understood my question.

I have a form with three views, each for a particular case of the form.

Within those three views is a textbox that must compile a phrase based on
the information compiled in the form. The phrase that is gramatically
different based on which view you are using. A user would not use all three
views, but would choose the view based on the requirements at the time.
(Sick, Approved Absence or Holiday)

As you state, the textbox is indeed linked to the data, not the view and as
such, even though a text box exists on three different views, it only has one
default value function.

I was looking for a method to change the default value function based on
which view is opened, thereby faking an equation for each view. As you can
see from the code below, however I couldn't find a property or method on the
node object that allows me to define the default value function.
nodeNote.something.somethingelse = strDefaultFormula

It it not possible to change this equation at run time?

I do not want to create three different text boxes, as data should be
contained within the same XML element.

thanks again for your quick reply...

nick
public void OnSwitchView(DocEvent e)
{

// grab notes node
IXMLDOMNode nodeNote =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:richiesta/my:note")

// look which form we are on, and set the default value formula
switch (thisXDocument.View.Name.ToString()) {
case "ferie":
thisXDocument.UI.Alert("ferie");
// set string for default formula
strDefaultFormula="concat("hello","worldA")
break;
case "permesso":
thisXDocument.UI.Alert("permesso");
// set string for default formula
strDefaultFormula="concat("hello","worldB")
break;
case "malattia":
thisXDocument.UI.Alert("malattia");
// set string for default formula
strDefaultFormula="concat("hello","worldC")
break;

default:
thisXDocument.UI.Alert("case crashed out.");
break;
}
nodeNote.something.somethingelse= strDefaultFormula
}


I am having difficulty finding which property of nodeNote I need to change.
As there doens't seem to be any reference to this on the web, perhaps it
can't be changed, and in that case, how do I do such a thing?

thanks again,

nick
 

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