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

Question

Question

Modern Designer JavaScript Help to Populate Field

asked two days ago Show version history

I am working on recreating a form that was created in the Classic Designer and I'm moving it to the Modern Designer.

What I need to do is based on the current user task step, I need to populate a field (FieldID 8) with a value. So if the step name contains "Approval Level 1" then I need it to insert a 1 into Field 8. Here is the JavaScript that I created for it, but it does not populate the field when I preview it and change the step in the top right. I wasn't sure if there is something wrong with my JavaScript or if it is because the preview doesn't reload the form when the value is changed.

LFForm.onFormLoad(function () {
    var stepName = LFForm.getStepName();

    if (stepName.includes("Approval Level 1")) {
        LFForm.setFieldValues({ fieldId: 8 }, "1");
    } else if (stepName.includes("Approval Level 2")) {
        LFForm.setFieldValues({ fieldId: 8 }, "2");
    } else if (stepName.includes("Approval Level 3")) {
        LFForm.setFieldValues({ fieldId: 8 }, "3");
    } else if (stepName.includes("Approval Level 4")) {
        LFForm.setFieldValues({ fieldId: 8 }, "4");
    }
});

Using Forms 11.0.2311.50564

0 0

Replies

replied one day ago

Hi Blake, try this for the setFieldValue

 

LFForm.setFieldValues({fieldId: 8},{value: "1"});

LFForm.setFieldValues({fieldId: 8},{value: "2"});

LFForm.setFieldValues({fieldId: 8},{value: "3"});

LFForm.setFieldValues({fieldId: 8},{value: "4"});

0 0
replied one day ago

Thanks, but no dice.

0 0
replied one day ago Show version history

add a consolelog and see if you are even get the stepname.

LFForm.onFormLoad(function () {
    var stepName = LFForm.getStepName();

        console.log(stepName);

    if (stepName.includes("Approval Level 1")) {
        LFForm.setFieldValues({ fieldId: 8 }, "1");
    } else if (stepName.includes("Approval Level 2")) {
        LFForm.setFieldValues({ fieldId: 8 }, "2");
    } else if (stepName.includes("Approval Level 3")) {
        LFForm.setFieldValues({ fieldId: 8 }, "3");
    } else if (stepName.includes("Approval Level 4")) {
        LFForm.setFieldValues({ fieldId: 8 }, "4");
    }
});
0 0
replied one day ago

Two things:

1. There is no onFormLoad in the LFForm object. It automatically runs your script when all form fields are available.

2. The current step name is just a property of the LFForm object if you log the entire LFForm object you will see all of the properties

https://doc.laserfiche.com/laserfiche/en-us/Content/Resources/BusinessProcesses/Javascript-and-CSS/TheLFFormObject.htm?Highlight=step#TheLFFormProperties

 

const stepName = LFForm.step.name;

if (stepName === "Approval Level 1") {
        LFForm.setFieldValues({ fieldId: 8 }, "1");
 } else if (stepName === "Approval Level 2") {
        LFForm.setFieldValues({ fieldId: 8 }, "2");
 } else if (stepName ==="Approval Level 3") {
        LFForm.setFieldValues({ fieldId: 8 }, "3");
 } else if (stepName === "Approval Level 4") {
        LFForm.setFieldValues({ fieldId: 8 }, "4");
 }

 

0 0
replied one day ago

Thank you, Zach. I am guessing that when you change the Preview Configuration option that it does not execute the JavaScript again? The reason I ask is because it didn't populate the field in question when I did it.

0 0
replied one day ago

That is correct, we decided not to implement that on the preview page because it would more likely cause more harm than good (and no one complained about it yet haha)

You can run it in the console after switching the step in the preview toolbar to show it works

0 0
replied 20 hours ago

I wouldn't complain right now either if I was on 12. Hopefully we can get there in the next few weeks after resolving some of the issues we ran into during our attempted upgrade.

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

Sign in to reply to this post.