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

Discussion

Discussion

Passing Variable to Form URL to populate Field

posted on May 17, 2024 Show version history

Hi all, 

I thought I had this working before but it does not seem to be working. Basically trying to pass a variable from one form called xt to another form variable called test.

 

form_name?test={/dataset/xt}

 

Why is this not working? I set xt to have a default value of 5 or manually enter 5 but it just passes nothing when i click the link its just =

Thanks

 

0 0
replied on May 18, 2024

The value won't be set in the variable until the form is submitted, even if it is defaulted.  I've done something similar to move a value in a custom HTML field in a live form before submission, but it requires a lot of JS to work with the HTML.  If you go to the Solution Template list in forms and load the Gifted and Talented Parent Report, you can take the coding in the JS and adjust it with your fields.  (I've not tested it on a default variable, but the values I grab in that form are not set either.)  

I have dashboards that show URL links for other forms but I create them in workflow first and pull from SQL.  If you are using a default value, could you not create the link first and the use a lookup in your dashboard?

0 0
replied on May 17, 2024

Thanks Angela, 

 

I have tried defaulting the xt field and entering data manually. I am using on prem here.

I am not submitting the form at the moment, I am trying to create a dashboard when a user clicks on the hyper link it passed the value that is then used for a lookup.

Just not sure why the variable passed doesn't get passed on.

 

0 0
replied on May 19, 2024

Variables only exist in that format when they have been set by a prior submission or workflow. To support dynamic field values without submitting the form, the code you want to use looks like this:

Set the IDs at the top to the fields you need. The updateHTML function will define the logic needed to create the link, and you can reuse it right away (to support default fields) and onFieldChange (to handle when the field is modified by the user).

const watchFieldId = 2;
const htmlLinkFieldId = 3;

const updateHTML = async (htmlFieldId, fieldValue, linkText) => {
  const link = `https://mywebsite/forms/testform?test=${fieldValue}`;
  const text = linkText ?? link;
  await LFForm.changeFieldSettings(
    { fieldId: htmlFieldId },
    {
      content: `<a href="${link}">${text}</a>`,
    }
  );
};

LFForm.onFieldChange(
  async () => {
    const value = LFForm.getFieldValues({ fieldId: watchFieldId });
    const fieldValue = Array.isArray(value) ? value[0] : value;
    if (fieldValue) {
      await updateHTML(htmlLinkFieldId, fieldValue);
    }
  },
  { fieldId: watchFieldId }
);
// Handle default values if needed
const value = LFForm.getFieldValues({ fieldId: watchFieldId });
const fieldValue = Array.isArray(value) ? value[0] : value;
if (fieldValue) {
  updateHTML(htmlLinkFieldId, fieldValue);
}

 

1 0
replied on May 17, 2024 Show version history

Is {/dataset/xt} a hidden field that you have defaulted?  When you complete the first form do you see the value in monitor?  

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

Sign in to reply to this post.