Making form's data read-only

J

JR

I'm wondering if someone tell tell me what all of my options are for making a form's data read-only, once it has been submitted. I'm sure my options are more limited because the powers-that-be have decided that we should use javascript instead of managed code. (don't get me started...)

We're customizing the Status Report form to so that our project mgrs. can save draft copies of their monthly status reports; but once they are submitted, they can no longer make any changes. Once a report has been submitted, the financial data will roll-up into a series of higher level reports, which is why we don't want the numbers to change after the fact. The reports themselves will ignore the draft reports, only reporting on the submitted versions.

The reports are being saved the to form library as XML data rather than submitting information to a database.
 
R

redbastid

If you right-click on the text box and select "Text box properties",
there is an option to make the control read-only. It's under the
DISPLAY tab. You can also disable INSERT/DELETE on repeating
containers by right-clicking on the section/repeating object. I
haven't been able to make a date-picker readonly, though. If somebody
knows how to do that, I'd like to know!
 
J

JR

I need to make the entire form read-only, after it has been submitted. Until then, the user's still need to be able to enter data.. :)
 
S

Scott L. Heim [MSFT]

Hi,

Just for reference, you are not limited to JScript or VBScript - you can
write C#.NET or VB.NET code behind an InfoPath project - you simply need to
download the .NET toolkit for InfoPath - once you do, you will have a new
option in your VS.NET to create an InfoPath solution.

You can get the Toolkit using the following URL:

http://www.microsoft.com/downloads/details.aspx?FamilyID=7e9ebc57-e115-4cac-
9986-a712e22879bb&DisplayLang=en

Now - in regard to your question, with InfoPath you do not have
programmatic access to the controls. As such, there are a few options you
have:

- Use Digital Signatures to allow the users to digitally sign the data once
they are ready to submit it. This insures data integrity.
- With some of the controls, you can use Conditional Formatting to make
those controls read-only. So theoretically you could have a check box that
gets set to "True" when the Submit occurs and then use Conditional
Formatting on the controls to set them to read-only if the check box is
true. This will still allow data to be entered until the submit occurs.

The downside to this is that all controls do not have a "read-only"
attribute - as such, the feasibility of this option will depend on the
controls you are using.

I hope this helps!

Scott L. Heim
Microsoft Developer Support

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

JR

Hi Scott,

Thanks for the feedback. I know I'm not limited to JScript or VBScript, but unfortunately; for this project, that's what we've been mandated to use. Why or how this was determined I have no idea, but I'm just the whipping boy.. :)

Since I have some date picker controls, which do not have a read-only property; it looks like I'm going to have to go the route of digital signatures, which is what I suspected in the first place. I just wanted to make sure there wasn't any other options available to me.

I'll take a look into what is involved for those and go from there. Thanks again for your response.

- JR
 
S

Scott L. Heim [MSFT]

Hi JR,

Even thought the Date Picker control does not have a "read only" property,
have you looked at using Conditional Formatting? For instance, you could
check another control (i.e. a check box) and if it is true, then the Date
Picker control could be set to read-only.

I hope this helps!

Best Regards,

Scott L. Heim
Microsoft Developer Support

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

JR

Scott;

No I haven't. I'm still a bit new to the whole Sharepoint / Infopath thing. Can you give me some additional information, or examples of what you're talking about? That might also suit our needs.

Thanks in advance.
 
S

Scott L. Heim [MSFT]

Hi JR,

Here are some sample steps to demonstrate what I mentioned:

- Create a new, blank InfoPath solution
- Add a check box (named: Submitted), a Date Picker (named: myDate) and a
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 choose Set a field's value
- Click the button next to Field, select Submitted and click OK
- In the Value box, enter: true

** NOTE: The word "true" above must all be lower case! **

- Click OK 4 times to get back to your form
- Right-click on myDate and choose Properties
- Select the Display tab
- Click the Conditional Formatting button
- In the first box, select Submitted
- In the second box, select "is equal to"
- In the last box, select TRUE
- Enable the Read-only option
- Click OK 3 times to get back to your form
- Preview the form
- Select a date - notice it enters what you selected
- Click the button - the check box should now be checked and you can no
longer modify the date field!

Now - obviously in the real world, your button would execute the "submit"
functionality (do this with a Rule) and it would also then set this check
box to "true." In addition, the check box does not actually need to appear
on the form unless you want it to. So in this manner, you could add
Conditional Formatting to each control that basically says: "if Submitted
equals true Then this control is now read-only."

I hope this helps!

Scott L. Heim
Microsoft Developer Support

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

JR

Hi Scott,

That sort of ties in to some of the other things that I need to do as well. We want the form to to simply submit to a Sharepoint forms library; so we just created a data connection to the library and used the submit wizard to execute that functionality.

However, we would also like to record the date and time the form was submitted as part of the form itself. So basically, if the submitted date/time field contains a value (equivalent of the checkbox being true); I could set all the fields to read-only, correct?

So now my question becomes, how exactly would I do this on the submit event and still submit the form to the library as we currently have setup? Do I need to recreate all the work of the wizard in the OnSubmitEvent handler? If so, can you again point me in the right direction?

Thanks again for everything.

-JR
 
S

Scott L. Heim [MSFT]

Hi JR,

If I have understood correctly, you have setup a data connection for
submission to your Sharepoint and are simply using the default "submit"
button to submit the form. If this is the case, the change should be minor:

** Make a backup copy of your InfoPath solution! *

- Right-click on your current Submit button and choose Properties
- Currently, your "Action" probably indicates Submit - change this to Rules
and Custom Code
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box choose Submit Using a data connection, select your
submit connection and click OK
- Click Add Action
- From the Action box choose Set a field's value
- Click the button next to Field, select the field where you want to enter
the date and time and click OK
- Click the button next to Value, click Insert Function, choose Date and
Time from the Categories list, select Now from the Functions list and click
OK
- Lastly, you will need to add the Conditional Formatting to your controls
to look to the date/time field for a value and take the appropriate action

Let me know if this is what you needed! (I hope I haven't forgotten any
steps! <G>)

Scott L. Heim
Microsoft Developer Support

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

JR

Scott,

Perfect, thanks. I've tried this on a couple fields and it appears to be working as I expected. Once a form has been submitted, will it automatically prevent it from being saved or submitted again; or will I have to impose some custom methods to disable the menu commands in InfoPath?
 
S

Scott L. Heim [MSFT]

Hi JR,

That's great to hear!

With regard to allowing a "re-submission" - you will need to implement that
logic. As a quick thought, you could add a "Condition" to your Submit Rule
to only execute if your date/time field is blank - I think that would
provide the functionality you need.

Take care,

Scott L. Heim
Microsoft Developer Support

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

JR

Hi Scott,

Actually; that thought occurred to me just before your post showed up.. heh. :)

However, I don't think that will work for the save event. Am I correct in assuming that the only thing I can do is to write a custom save event handler, check if the date/time field contains data, and disable it if it does, right?
 
S

Scott L. Heim [MSFT]

Hi JR,

I apologize but I don't think I follow - are you implementing both a "save"
and "submit?" If so, are they on different buttons?

Scott L. Heim
Microsoft Developer Support

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

JR

Scott;

Yes, we have both; but we're not using buttons; just the Infopath menus at this point. It will probably be easier for our users this way anyway as they are already used to using the menus for the current versions of the report built in Word and Excel; but we could go the button route if it's easier.

The save and submit functionality differ in that saving the form is essentially a draft copy, whereas the submit will make it official; hence the submitted date/time and making the fields read-only when it is submitted.
 
S

Scott L. Heim [MSFT]

Hi JR,

In that case, yes - you will simply need to override the "Save" event and
handle it appropriately for your organization.

Best regards,

Scott L. Heim
Microsoft Developer Support

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

JR

Hi Scott;

Just when I thought I had it, I ran into one other issue. My submit event is controlled by rules, so when the rules set the submitted date as the form is submitted; the user is then prompted to save the changes (because the date was changed).

However, in my save handler, I've disabled saving the form once it's submitted which actually prevents the submitted date value from being set. Any ideas on how to work around this? Am I going to have to switch the submit event from using rules to custom code?

Also, one other issue has cropped up.. I currently have the data connection set to publish the form to a given form library on a given site. I have now learned this form will be located a library on several sites, so is there a way to have the data connection use the "current" site and library to publish to?

Thanks again for everything, you've been a tremendous help.
 
S

Scott L. Heim [MSFT]

Hi JR,

Yes - I would remove the Rule for the submit and simply use code:

XDocument.Submit

This way you have more control.

In regard to where the form is submitted to - I may not understand
correctly but let's hash this out: typically if you are going to have your
XSN used in multiple sites, it will need to be "published" to those sites
(so your users can click the "Fill out this form" option.) As such, the
forms created will be "published" to the same library.

Now you can have your form setup so that only 1 library is used to "Fill
out this form" and then have multiple connections to submit to other
libraries but those won't be able to be used for creating new
forms...unless you have published to those libraries.

Does that make sense or did I make it worse? <G>

Scott L. Heim
Microsoft Developer Support

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

JR

Hi Scott;

We decided to go a bit of a different route and remove the save ability altogether. We're just going to use submit and have a drop down list with the choices of Final or Draft. This way, when the users chooses draft and submits the form, it essentially just saves it; but when they choose final; it's sets the appropriate flag and locks the form down.

I've managed to come up with some code that should allow me to determine the current form library that is in use and publish the form back to it. So I will change the submit method from using rules to using custom code. This should alleviate the other concern I had.

Hopefully, this means I'm in good shape for the remainder of my project and you won't need to keep checking up on me! :)

Thanks again for all your help - it was greatly appreciated and saved me countless hours.
 
S

Scott L. Heim [MSFT]

Hi JR,

That is great to hear - thank you for the update!

Take care,

Scott L. Heim
Microsoft Developer Support

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

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