You are viewing limited content. For full access, please sign in.

Question

Question

Forms New Designer - how to get the approval comments using Javascript

asked on April 15

I have designed a Forms process using the New Designer on LF Cloud and I have provided two buttons on the form, one for "Approve" and the other one for "Reject".

I would like the form to enforce "Comments" to be provided if they press on the "Reject" button.

I have seen a code sample in the Laserfiche documentation that seems very close to do what I need but I'm trying to get that "Comments" field content using the following code:

 

LFForm.onFormSubmission(async function (event) {
 // Get the value of the clicked submission button
 const userAction = event.data.action.value;
 const approvalComments = LFForm.getFieldValues({ fieldId: 2});
 if (userAction === "Reject" && approvalComments === "") {
  await LFForm.showFields({ fieldId: 2 });
  return {error: "Please add comments in order to approve."};
 } else {
  await LFForm.hideFields({ fieldId: 2 });
 }
});

In that example, it is using field 2 but wondering how can I get the "Comments" system multi-line input value...

1 0

Replies

replied on April 15

You can do this by adding a single line field to your form and keep it hidden.  The field will capture the Action button result and then you can use a Field rule to Validate the Comment box as Required when that field has the value from the Reject button.

Use this JS: 

LFForm.onFormSubmission(async function (event) {
  await LFForm.setFieldValues({variableName: "YourSingleLineFieldVariable"}, event.data.action.value);
});

 

0 0
replied on April 15

Thanks Angela for this answer.

I mainly wanted to use the default "Comments" box from Laserfiche instead of adding my own field and managing my custom comments field behavior throughout the approval process.

I may have no other choice than going with your suggestion if there is no way to get the TEXTAREA content from the Laserfiche default comments field.

0 0
replied on April 15

Supporting the comments field from the LFForm object is on my todo list. For now Angela's workaround is the best way forward 

1 0
replied on April 15

This approach does use the built in Comment box, but you do have to use the additional field to apply the Field Rule.

0 0
replied on April 16

Hi again Angela,

The example you provided does copy the event from the action button being pressed into that hidden field. this is not really what I'm trying to perform here.

I need to see if the "Comments" field is empty or not, so I can show a message to the user to fill up a reason in the "Comments" field.

As Zachary said, it's on his todo list, unless someone else has an idea.

 

 

 

0 0
replied on April 16

If you set a field rule on the single line field, you can make the comment box required, as well as show an HTML message that the comment box needs to be completed. 

 

0 0
replied on August 11

I'd love to see this as a LFForm method too. It can get overwhelming to continue to add fields just to perform functionality on the form. 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.