help with the if() code

J

Jeffshex

I'm addressed this in a previous topic but still no avail.
On Submit On_Click I need to run a submit, then an If statement that says if
the node my:WeekTotal < 35 then print. If it's above 35 I don't need it to
do anything but close like normal. Here's what someone else recommeded to me
but it didn't work:

XDocument.Submit();
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){
XDocument.PrintOut();
}

any help would be nice
PS:I'm still not 100% if this needs to be a Fully trusted form.
 
S

Scott L. Heim [MSFT]

Hi Jeff,

I believe it was me who suggested the test - what happened? Did it produce
an error or just ignore the test?

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffshex

You recommeded it, some one else told me to try that code. It returns an
error on this line:
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){

Do you know...maybe instead of printing, can it just say...you are under 35
hours and then they can choose to go back to the form or continue on with the
submit.
That would work just as well if not better for me.
 
S

Scott L. Heim [MSFT]

Hi Jeff,

If all you need to do is "alert" the user, what about using the built-in
data validation?

- On the field that contains the hours, right-click and choose Properties
- Click the Data Validation button
- Click Add
- In the first drop-down box choose "Select A Field or Group" and use the
builder to select the text box that has the total hours
- In the second drop-down, choose "Is Less Than"
- In the last drop-down, choose "Type a Number" and then enter 35
- Choose the Error Alert Type and then enter some text for the Screen Tip
and Message
- Click OK until you are back to your form and then test - if the hours are
< 35, you should see a red box around the field!

Would this work?

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jeffshex

The validation will completely prevent them from having less than 35 hours.
There are times though when they will have less than that. I just want them
to know that what they have is less than, but they can cancel the submit and
make changes or just hit ok and continue with the submission.
 
J

Jeffshex

There's only 1 WeekTotal field. Not quite sure of the full xpath but i'll
mess with it.
I have the WeekTotal field format set as decimal(auto), will that cause a
problem?
 
J

Jeffshex

It doesn't matter, just didn't know if infopath was crabby about that.

Greg Collins said:
Do you want to print before submit?

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



Also, do i need to have the print if statement before the submit in the code?

Greg Collins said:
Is there more than one WeekTotal field? If so then the XPath should be more specific. You also might want to try a more definite conversion to an integer...

Also, are you using JScript or C#? The code you presented below assumed you were using C# for the conversion to "(int)" but then mixed in non-managed code by calling "XDocument" instead of "thisXDocument". Here's a fix for both C# and JScript just in case.

----------
C#:
----------
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();

----------
JScript:
----------
if(parseInt(XDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
XDocument.PrintOut();

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



I'm addressed this in a previous topic but still no avail.
On Submit On_Click I need to run a submit, then an If statement that says if
the node my:WeekTotal < 35 then print. If it's above 35 I don't need it to
do anything but close like normal. Here's what someone else recommeded to me
but it didn't work:

XDocument.Submit();
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){
XDocument.PrintOut();
}

any help would be nice
PS:I'm still not 100% if this needs to be a Fully trusted form.
 
J

Jeffshex

Here's what I put in the edit form code for the submit:

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();
thisXDocument.Submit();
}

when i press submit it says there was an error in the code and doesn't tell
where.
any idea?


Greg Collins said:
Do you want to print before submit?

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



Also, do i need to have the print if statement before the submit in the code?

Greg Collins said:
Is there more than one WeekTotal field? If so then the XPath should be more specific. You also might want to try a more definite conversion to an integer...

Also, are you using JScript or C#? The code you presented below assumed you were using C# for the conversion to "(int)" but then mixed in non-managed code by calling "XDocument" instead of "thisXDocument". Here's a fix for both C# and JScript just in case.

----------
C#:
----------
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();

----------
JScript:
----------
if(parseInt(XDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
XDocument.PrintOut();

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



I'm addressed this in a previous topic but still no avail.
On Submit On_Click I need to run a submit, then an If statement that says if
the node my:WeekTotal < 35 then print. If it's above 35 I don't need it to
do anything but close like normal. Here's what someone else recommeded to me
but it didn't work:

XDocument.Submit();
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){
XDocument.PrintOut();
}

any help would be nice
PS:I'm still not 100% if this needs to be a Fully trusted form.
 
J

Jeffshex

Ok, last time here...still gettin an error and cannot complete action because
an error in the forms code.

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(parseInt(XDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
XDocument.PrintOut();
XDocument.Submit();
}

I'm bout all out of ideas.
:(

Greg Collins said:
The fact that you have a "function" indicates you are using JScript and not C#, but you implemented the C# code. Switch to using the JScript code.

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



Here's what I put in the edit form code for the submit:

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();
thisXDocument.Submit();
}

when i press submit it says there was an error in the code and doesn't tell
where.
any idea?


Greg Collins said:
Do you want to print before submit?

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



Also, do i need to have the print if statement before the submit in the code?

Greg Collins said:
Is there more than one WeekTotal field? If so then the XPath should be more specific. You also might want to try a more definite conversion to an integer...

Also, are you using JScript or C#? The code you presented below assumed you were using C# for the conversion to "(int)" but then mixed in non-managed code by calling "XDocument" instead of "thisXDocument". Here's a fix for both C# and JScript just in case.

----------
C#:
----------
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();

----------
JScript:
----------
if(parseInt(XDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
XDocument.PrintOut();

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



I'm addressed this in a previous topic but still no avail.
On Submit On_Click I need to run a submit, then an If statement that says if
the node my:WeekTotal < 35 then print. If it's above 35 I don't need it to
do anything but close like normal. Here's what someone else recommeded to me
but it didn't work:

XDocument.Submit();
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){
XDocument.PrintOut();
}

any help would be nice
PS:I'm still not 100% if this needs to be a Fully trusted form.
 
J

Jeffshex

Of course after I get it to work the manager wants a confirmation box instead.
Is it possible to switch out the print() with a confirmation box, kinda like:
function CTRL186_7::OnClick(eventObj)
{
// Submit code
if(parseInt(XDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
var UnderHours = window.confirm("You're under 35 hours. Click ok to submit
or cancel to make changes.");
if (UnderHours) {XDocument.Submit();}
}

That code is probably wrong, but am i close?
Thanks again for all your help.

Greg Collins said:
Did you already get asked whether your form security is set to Full Trust? Use of "PrintOut()" requires full trust.

That's all I can think of at this point.

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



Ok, last time here...still gettin an error and cannot complete action because
an error in the forms code.

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(parseInt(XDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
XDocument.PrintOut();
XDocument.Submit();
}

I'm bout all out of ideas.
:(

Greg Collins said:
The fact that you have a "function" indicates you are using JScript and not C#, but you implemented the C# code. Switch to using the JScript code.

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



Here's what I put in the edit form code for the submit:

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();
thisXDocument.Submit();
}

when i press submit it says there was an error in the code and doesn't tell
where.
any idea?


Greg Collins said:
Do you want to print before submit?

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



Also, do i need to have the print if statement before the submit in the code?

:

Is there more than one WeekTotal field? If so then the XPath should be more specific. You also might want to try a more definite conversion to an integer...

Also, are you using JScript or C#? The code you presented below assumed you were using C# for the conversion to "(int)" but then mixed in non-managed code by calling "XDocument" instead of "thisXDocument". Here's a fix for both C# and JScript just in case.

----------
C#:
----------
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();

----------
JScript:
----------
if(parseInt(XDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
XDocument.PrintOut();

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



I'm addressed this in a previous topic but still no avail.
On Submit On_Click I need to run a submit, then an If statement that says if
the node my:WeekTotal < 35 then print. If it's above 35 I don't need it to
do anything but close like normal. Here's what someone else recommeded to me
but it didn't work:

XDocument.Submit();
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){
XDocument.PrintOut();
}

any help would be nice
PS:I'm still not 100% if this needs to be a Fully trusted form.
 
J

Jeffshex

What's with the 4 after the do you wish to continue line?

Greg Collins said:
There is a confirm method in InfoPath SP1.

XDocument.UI.Confirm(prompt As String, buttons As XdConfirmButtons) As XdConfirmChoice

example with Yes/No buttons:

XDocument.UI.Confirm("Do you wish to continue?", 4);

Look up in the InfoPath help for more details on how to use this method.


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



Of course after I get it to work the manager wants a confirmation box instead.
Is it possible to switch out the print() with a confirmation box, kinda like:
function CTRL186_7::OnClick(eventObj)
{
// Submit code
if(parseInt(XDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
var UnderHours = window.confirm("You're under 35 hours. Click ok to submit
or cancel to make changes.");
if (UnderHours) {XDocument.Submit();}
}

That code is probably wrong, but am i close?
Thanks again for all your help.

Greg Collins said:
Did you already get asked whether your form security is set to Full Trust? Use of "PrintOut()" requires full trust.

That's all I can think of at this point.

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



Ok, last time here...still gettin an error and cannot complete action because
an error in the forms code.

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(parseInt(XDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
XDocument.PrintOut();
XDocument.Submit();
}

I'm bout all out of ideas.
:(

Greg Collins said:
The fact that you have a "function" indicates you are using JScript and not C#, but you implemented the C# code. Switch to using the JScript code.

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



Here's what I put in the edit form code for the submit:

function CTRL186_7::OnClick(eventObj)
{
// submit code
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("//my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();
thisXDocument.Submit();
}

when i press submit it says there was an error in the code and doesn't tell
where.
any idea?


:

Do you want to print before submit?

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



Also, do i need to have the print if statement before the submit in the code?

:

Is there more than one WeekTotal field? If so then the XPath should be more specific. You also might want to try a more definite conversion to an integer...

Also, are you using JScript or C#? The code you presented below assumed you were using C# for the conversion to "(int)" but then mixed in non-managed code by calling "XDocument" instead of "thisXDocument". Here's a fix for both C# and JScript just in case.

----------
C#:
----------
if(Convert.ToInt32(thisXDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
thisXDocument.PrintOut();

----------
JScript:
----------
if(parseInt(XDocument.DOM.selectSingleNode("/my:FullXPath/my:WeekTotal").text) <= 35)
XDocument.PrintOut();

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



I'm addressed this in a previous topic but still no avail.
On Submit On_Click I need to run a submit, then an If statement that says if
the node my:WeekTotal < 35 then print. If it's above 35 I don't need it to
do anything but close like normal. Here's what someone else recommeded to me
but it didn't work:

XDocument.Submit();
if((int)XDocument.DOM.selectSingleNode("//my:WeekTotal").text <= 35){
XDocument.PrintOut();
}

any help would be nice
PS:I'm still not 100% if this needs to be a Fully trusted form.
 

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