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

Discussion

Discussion

Update Field Value with Current Step using JavaScript

posted on March 6 Show version history

I am currently trying to get the values in a dropdown list to change depending on the current step. I am not very good with JavaScript, but I have the following that mostly works.

const updateProbationDropdown = async () => {
    var mNum = LFForm.getFieldValues({fieldId: 71});
    if (mNum.match(/.*Probation.*/)) {
       await LFForm.changeFieldOptions( { fieldId: 40 }, [{label: "Current"},{label: "Ending Employment"}], "replace" );
    } else {
        // do stuff when it is not probation

    }
}

// Check on change
LFForm.onFieldChange(updateProbationDropdown, {fieldId: 71});

// Check on form load
updateProbationDropdown()

Where fieldId 41 is the dropdown list.
I have a SQL Stored Procedure updating fieldId71 with the Step Name. However, the lookup is only performed once, and the field value becomes static for the following tasks/steps.

Is it possible to either update fieldId 71 JavaScript to get the current step name? Or, get the current step name in the JavaScript itself?

 

We're using the latest v12 Forms

0 0
replied on March 7 Show version history

Here's the trick.

Add a Custom HTML element on your form (you can keep it hidden with Field Rules or CSS if you don't want the user to see it).  Populate the element with the following:   {/_current_step_name}

Note that you want to fill this in on the code view of Custom HTML element, not the formatted text view, otherwise you'll end up with a bunch of extra HTML tags that you don't want.

You want this:

You don't want this:

The value of {/_current_step_name} is going to be loaded each time the form is opened, and because Custom HTML elements do not store their value, it won't be impacted by prior submissions, so it is updated every time.

Then you can just retrieve the value of the Custom HTML element to get the step name at any given time.  

let stepName = LFForm.getFieldValues({fieldId: 1});
console.log(stepName);

 

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

Sign in to reply to this post.