How can I assign a Jscript function return value to a textbox by using a Rule?

A

A.M

Hi,



I have a Jscript function that returns a value based on some calculations.



How can I show the return value of this function within a textbox by using a
Rule?



I know that it is easy to do this job by using a button (because you can use
code to handle the click event), but I need the functionality upon any
change on other textboxes. The problem is you cannot assign code to textbox
change event.



Thank you,

Alan
 
A

A.M

Hi Scott,



Thank you for reply.



I've gone through that BLOG post. That technique provides totally different
thing.

It helps you to use Jscript function check conditions (true/false).



It doesn't help you to assign value to textboxes. If you attempt to modify
any textbox value within that Jscript function, InfoPath pops up an error
and complains that you are modifying a read-only value. I think all
textboxes become read-only when you are checking any conditions within rules
or conditional formatting.



I really need that functionality badly, could you think of anything else?



Thank you,

Alan
 
S

Scott L. Heim [MSFT]

Hi Alan,

I see what you mean. What you need is doable though...try following these
steps to see if this gets you to where you need.

- Create a new, blank InfoPath form
- Add a text box and button to the form
- Right-click on the button and choose Properties
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box select: Set a field's value
- Click the button next to the Field box, select field1 and click OK
- Click the "fx" button next to the Value field, click Insert Function and
from the Date and Time category, choose the "now" function and click OK.
(It's really not important what function you choose here but we cannot
directly add what we need into the Designer here. As such, this is merely a
"place holder" so we can easily find this function in the Manifest.XSF when
we open it with Notepad.)
- Click OK 5 times to get back to your form
- Load the script editor
- Add the following function:

function Test()
{
var i = 5;
return i * 10;
}

- Save and close the script editor
- From the File menu choose Extract Form Files and extract these to a
location of your choice
- Close InfoPath
- Locate the extracted files and open Manifest.XSF with Notepad
- Locate the following entry:

expression="xdDate:Now()"

- Change this to:

expression="xdExtension:Test()"

- Add the xdExtension namespace as per the BLOG entry
- Save and close Notepad
- To test, simply double-click Manifest.XSF and click the button - you
should see the value of 50 in the box!
- Assuming this works as expected, you can right-click on Manifest.XSF,
choose Design and then from the File menu choose Save As and save this back
as an XSN file.

So in your scenario Alan, you will need to add rules to set the values of
your fields to some dummy value (i.e. now()) and then change these in the
Manifest as needed.

Let me know how this works for you!

Best regards,

Scott L. Heim
Microsoft Developer Support

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

Gregs List Acct

I wonder if this thread will still be watched...

I did the same steps below: editing the manifest for to use my function and
updating the xdExtension refrence. When I run the form however, I get an
error:

Namespace 'http://schemas.microsoft.com/office/infopath/2003/xslt/extension'
does not contain any functions.

I'm using VBScript vs. jscript, but I would hope that wouldn't be a factor.

I hope I can solve this. Right now I've got a messy solution that checks
the record onAfterUpdate to determine if the value needs a default --- which
is a GUID in my case.

thanks!
Greg
 

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