Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How to disable form fields based on user and/or workflow step

Avatar

Former Community Member
Is there a good strategy for disabling (ie make read-only) various form fields based on the current user and/or the current stage of the workflow you are in?



Thanks
2 Replies

Avatar

Former Community Member
I have a strategy that I used in one of my forms. At a certain point in the workflow, a type of user in the workflow would open the form and the requirement is to have the form read only for that type of user. So on a different form template, I used the below JavaScript on the layout ready event to make ALL the fields read only (it was quicker to do it this way instead of setting each field one by one, especially when a change is needed on all the forms), then I set the workflow fields and any other fields that I need to protected or open.



// Get the field containers from each page.

for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++) {

var oFields = xfa.layout.pageContent(nPageCount, "field");

var nNodesLength = oFields.length;



// Set the field property.

for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++) {

oFields.item(nNodeCount).access = "readOnly";

}

}



The code is from the Adobe_XML_Form_Object_Model_Reference.pdf produced by Adobe.



I hope it helps.

Stone.

Avatar

Level 9
Hi



I use a similar approach, but rather than using two different form templates (which can get problematic to manage), I create a hidden field somewhere on my form, called "Phase".



I set the value of Phase using the SetValue QPAC.



In a layout ready event (or actually any event), I have code something like:

if (Phase.rawValue == "Initiate") {

// Do something

} else if (Phase.rawValue == "Respond") {

// Do something different

}



This means that the logic for controlling how your form looks and how it behaves is controlled within the form, but you can adjust that behaviour within a workflow by setting the Phase variable.



I hope this works for you...



Howard