Copy link to clipboard
Copied
I am using below code in bookmark to lock group of fields in my acroform. I found this code in https://forums.adobe.com/message/8679934#8679934 made by George_Johnson. I used two bookmark for two user (User A & User B). What is happening, when User A locks the fields User B can unlock field by entering his/her password.
Is there any way so that if fields are locked by User A's password it will be unlocked only by User A's password. Same thing for User B's also.
Bookmark for User A:
(function () {
var f_prefix = "prod.";
// Your chosen password goes here
var pw = "rok123";
// Get a reference to the first field in the group
var f = getField(f_prefix).getArray()[0];
//Determine new readonly state, which is the opposite of the current state
var readonly = !f.readonly;
var readonly_desc = readonly ? "lock" : "unlock";
//Prompt user for the password only if unlocking
if (f.readonly) {
var resp = app.response({
cQuestion: "To " + readonly_desc + " the fields, enter the password:",
cTitle: "Enter password",
bPassword: true,
cLabel: "Password"
});
} else {
var resp = pw;
}
switch (resp) {
case pw:
getField(f_prefix).readonly = readonly;
app.alert("The fields are now " + readonly_desc + "ed.", 3);
break;
case null: // User pressed Cancel button
break;
default: // Incorrect password
app.alert("Incorrect password.", 1);
break;
}
})();
Bookmark for User B:
(function () {
var f_prefix = "prod.";
// Your chosen password goes here
var pw = "sam789";
// Get a reference to the first field in the group
var f = getField(f_prefix).getArray()[0];
//Determine new readonly state, which is the opposite of the current state
var readonly = !f.readonly;
var readonly_desc = readonly ? "lock" : "unlock";
//Prompt user for the password only if unlocking
if (f.readonly) {
var resp = app.response({
cQuestion: "To " + readonly_desc + " the fields, enter the password:",
cTitle: "Enter password",
bPassword: true,
cLabel: "Password"
});
} else {
var resp = pw;
}
switch (resp) {
case pw:
getField(f_prefix).readonly = readonly;
app.alert("The fields are now " + readonly_desc + "ed.", 3);
break;
case null: // User pressed Cancel button
break;
default: // Incorrect password
app.alert("Incorrect password.", 1);
break;
}
})();
Any help please.
You would need to save the information somewhere, then, for example in a (hidden) text field.
Set its value to "A" if user A locks the file, and then reset it when they unlock it, and the same with B.
Then you add a condition to both scripts checking that field's value before allowing them to unlock the fields.
Copy link to clipboard
Copied
What are the names of the fields for each user?
Copy link to clipboard
Copied
Field names are prod.product, prod.name, prod.details, prod.invest, prod.fhsdt, prod.id, prod.witname, prod.remidial.
Either user A or B can fill this fields from production department and send this to QA department. For QA dept. I am thinking of using button.
Thanks
Copy link to clipboard
Copied
So you want to disable user B from unlocking the fields if user A locked them (and vice versa), basically?
Copy link to clipboard
Copied
Yes you are right.
Copy link to clipboard
Copied
You would need to save the information somewhere, then, for example in a (hidden) text field.
Set its value to "A" if user A locks the file, and then reset it when they unlock it, and the same with B.
Then you add a condition to both scripts checking that field's value before allowing them to unlock the fields.
Copy link to clipboard
Copied
It would be great help if u give an example so that I can move forward.
Thanks
Copy link to clipboard
Copied
Hi
I have prepared my form in LCD, since I could not put the condition in acroform. In Xfa form, I used your logic and it worked absolutely!
You are a genius!
Thanks