Parameters for Single and Multiple Choice field

Hi everyone,

I was wondering whether it would be possible to fill in a parameter using Javascript in a Single and Multiple choice field. I'm able to fill in other types of field, but not these types.

Something like this isn't working:

fd.field('Choice_Field').value = urlParams.get('Value');

I'm using the 'normal' forms, not SharePoint. I want to pass the parameter using the url (so something like https://[URL].com/?Value=Test).

Many thanks in advance!

Kind regards,

Kelsey van der Heijden

Hello @kelseyvdheijden,

This code should work for Single Choice field:

fd.field('Choice_Field').value = urlParams.get('Value');

But for a Multiple Choice field, it must be an array, even if only it is one option:

fd.field('MultiChoice').value = ['Option 1'];

Thank you for your response, Margo.

I've tried your solution and I noticed something weird happend. The field is set correctly but it's not showing.

For example:
When I add this to the url:

https://[URL]/?Onderzoek=Intelligentieonderzoek

While using this code:

    fd.field('WelkTypeOnderzoekWiltUAanvragen').value = [urlParams.get('Onderzoek')];
    console.log("Value of field 'WelkTypeOnderzoekWiltUAanvragen' is: " + fd.field('WelkTypeOnderzoekWiltUAanvragen').value);

The logging shows me that the value is set correctly:
afbeelding

But it's not shown in the form itself (the box is not checked):
afbeelding

I have double checked the name of the field, it's correct.

Any ideas why it's not shown in the form?

Many thanks again!

@kelseyvdheijden,

Please use this code:

let optns = [];
optns.push(urlParams.get('Onderzoek'));
fd.field('Choice_Field').value = optns;

Thank you, Margo!

The weird thing is, when I try this code using the in-browser console, it works, but when I try this code with Plumsail the checkbox still isn't checked:
Fill in param Plumsail

Full code:

window.fd = fd;
window.$ = $;

 fd.rendered(() => {
     
    var queryString = window.location.search;
    var urlParams = new URLSearchParams(queryString);
    let optns = [];
    optns.push(urlParams.get('Onderzoek'));
    fd.field('WelkTypeOnderzoekWiltUAanvragen').value = optns;
    
 }

Field name: WelkTypeOnderzoekWiltUAanvragen
Field type: Multiple choice

Any ideas? I really appreciate your help. Thank you!

Hi Margo,

I found the solution. A time-out did the trick.

So this code works:

window.fd = fd;
window.$ = $;

 fd.rendered(() => {
     
    var queryString = window.location.search;
    var urlParams = new URLSearchParams(queryString);

setTimeout(() => {
    let optns = [];
    optns.push(urlParams.get('Onderzoek'));
    fd.field('WelkTypeOnderzoekWiltUAanvragen').value = optns;
    }, 500); 
 }

Thank you for your help!