Expand my Community achievements bar.

Setting field level security

Avatar

Former Community Member

I have created a form in LiveCycle in which two fields (Header and an Image block) need to be editable by one user type (e.g. power user), but should not be changeable by the end users.  They will only be able to fill in other fields in the form.  So far I have only been able to set form level security.  Is there a way to apply security to just these two fields, perhaps requiring a password, so that the power user can update these two fields as needed?

Thanks for any ideas you might have!

5 Replies

Avatar

Level 5

Hi Steve,

I think you'll need to programm this using Javascript.

However if you're using the LiveCycle Process Management module you can achieve this on the server side, and deliverying to the user only the form that he/she is able to fill in.

Diego

Avatar

Former Community Member

Hi Diego,

Thanks for responding.  We aren't using the LC PM module, so that takes one suggestion out of the running.

We tried some Javascript we found on the Acrobat forum (see below for what we used) - using it as an action with a bookmark, but it didn't work.  The guy who wrote the script on that forum looked at our file and thought that the problem was likely because the form was developed in LiveCycle.  We are not Java experts (or even close!), so we have no clue where to start.  And unfortunately if we cannot find a solution for this dilemma, we will have to decline a project from a client. 

So again, any thoughts or suggestions on where to go from here are greatly appreciated!

(function () {

    // Get one of the fields in the group
    var f = getField("private.name");

    // Determine new readonly state, which
    // is the opposite of the current state
    var readonly = !f.readonly;

    var readonly_desc = readonly ? "deactivate" : "activate";

    // Ask user for password
    var resp = app.response({
        cQuestion: "To " + readonly_desc + " the fields, enter the password:",
        cTitle: "Enter password",
        bPassword: true,
        cLabel: "Password"
    });

    switch (resp) {

    case "your_password": // Your password goes here
        getField("private").readonly = readonly;
        app.alert("The fields are now " + readonly_desc + "d.", 3);
        break;

    case null : // User pressed Cancel button
        break;

    default : // Incorrect password
        app.alert("Incorrect password.", 1);
        break;
}

})();

In this example, the fields that are controlled by this all have a field name prefix of "private", for example "private.name", "private.address", etc. This makes it easier to control the fields as a group, as I do in the line of code that begins: getField("private").readonly  If you don't use such a field naming convention, you'd have to have a separate such line for each field in the group.

Replace "your_password" above with one of your own. The first and last lines are not necessary, but do prevent the needless creation of document-global variables, which is a good thing.

Avatar

Level 5

Hi Steve,

You don't need to decline this project man! If you don't have the Javascript skills needed for the project, what if you outsource some parts?

Please send me an email with more details: diegosilva@eforms.com.br

Regarding to this code snipet, you'd need to write a code in Javascript for XFA forms, the ones developed using LiveCycle.

Avatar

Former Community Member

Hadn't thought about outsourcing it.  Will definitely keep that in mind.  The challenge will be to make sure that the cost of outsourcing doesn't eat all of the profit from the project.

It's not a high dollar gig, so the ROI might not be there.  Thanks for the ideas - and we'll reach out to you if we decide to look at outsourcing!

Avatar

Level 10

Hey Steve, the problem with that code is that it's Acrobat JavaScript not LiveCycle.

You can do what you need quite simply with app.response(), if you don't need anything too fancy. You can put it on a button click or I've also done it so you enter the password in a particular field that already exists on the form.

So the power user opens the form, enters the password and edits and then saves the form and it's back to being protected.

Put on the Click event of a button:

var dialogTitle = "Enter Password";

var reply = app.response("Enter password to edit this section.", dialogTitle);

if (reply == "Password") {

     fieldName.access = "open";

}

Or on the Exit event of a text field:

if (this.rawValue == "Password") {

     fieldName.access = "open";

}

Depending on the version of Acrobat (version 9 or later? not sure) you're targeting you can set the access at the subform level to control a bunch of objects or you could write a loop to run through a subform, or looking for fields with a particular name.