Lookup Field + automatic fill

I have 2 Sharepoint lists [UE60] and [PW_Bereichsleitung]. In the [UE60] list, I have inserted a lookup to the [PW_Bereichsleitung].

Question 1:
When I select the lookup field in Plumsail, the title automatically appears (which is correct). However, I would also like to display the [First name] field from the [PW_Bereichsleitung] list in the lookup.
I have already tried this via the lookup field [Extra fields] by entering “First name” there. However, nothing appeared there in the lookup field. I just can't figure out what I'm doing wrong.

Question 2:

When I select something in the lookup field, 3 text fields in the list [UE60] should be filled with the corresponding data from the list [PW_Bereichsleitung] after the selection. If I change the selection, the updated data should be inserted into the fields.


I have already tried everything possible. But I haven't had much to do with Javascript yet. Maybe you can help me with my problems, as I might need these points more often in the future.

Hi @Mick,

By adding new entries to the Extra fields property you make the Lookup retrieve them, but you need to run a separate JavaScript command to display them. You can include additional fields in the lookup options like this:

To fill in the extra field values into the form fields, try using this approach.

Hi Ilia,

I've already come across these tips, but I can't get any further. Either there is [nothing] in the lookup or only the [Title].

As I mentioned before, my scripting skills are minimal. I have tried to display the [Vorname] field from the list [PW_Bereichsleitung]. Unfortunately still without success. The field is there, as is the list. Here is my current script:

fd.spRendered(function() {
// Lookups erweitern
var lookup = fd.control('Lookup1');
lookup.extraFields = 'Vorname'; // get extra fields
//lookup.expandFields = ['Vorname']; // to access complex fields, expand them first
lookup.ready(() => {
function updateFields() {
console.log(lookup.value); // Prüfen des gesamten Lookup-Werts
console.log(lookup.value.Vorname); // Prüfen des Vorname-Werts
fd.field('Vorname').value = lookup.value.Vorname;
}
updateFields(); // update fields when the control is ready
lookup.$on('change', updateFields); // update fields whenever the lookup value is changed
});

Here is a look at the console:

Here the Lookup in Plumsail:

As a proposal: Would it be possible to create the script automatically in Plumsail if you type in one ore more "Extra fields"? ... maybe as a comment in the JS-Area?

Hi @Mick,

The script you've provided is for displaying the Vorname in a field called Vorname on the form, not for adding it to the lookup itself. The error in the console is likely caused by the lookup being empty.

Try adding this code to the script:

fd.spBeforeRender(function() {
    let template = '#: data.LookupValue # #: data.Vorname #';
    fd.control('Lookup1').widgetOptions = {
        template: template,
    }
});

Don't forget to add Vorname to the Extra fields property of the lookup. It's better to do this through the Form Designer's UI than with JavaScript.

Thank you @Lazarevskii Ilia,

so what exactly is the shortest way to add one Field (like "Vorname") to the Lookup.

adding the Name "Vorname" to [Extra field] in the designer AND which Code exactly in the JS Area? Sorry, but as I wrote - I tried different ways to do this, but without success. Either only the title was visible (this is the minimum) or nothing at all.

Hi @Mick,

Adding "Vorname" to extra fields and pasting this code in the JS editor should work:

fd.spBeforeRender(function() {
    let template = '#: data.LookupValue # #: data.Vorname #';
    fd.control('Lookup1').widgetOptions = {
        template: template,
    }
});

You can modify the "template" string to include more fields, just make sure to follow the same formatting:

let template = '#: data.LookupValue # #: data.Vorname # #: data.OneMoreField #';

Hi @IliaLazarevskii

Thanks a lot!!! This is working now.

Wouldn't it be helpful to add your script example to your Webpage for guys like me?
[Lookup field — Plumsail SharePoint Forms Documentation](https://Here for example)

Or even easier. If you type a field name into the [Extra fields] in the designer you show a list of all available fields from the Lookup-List. The user could choose which one he would like to add. Automatically the Script will be created in the JS Area.

Perhaps this is a crazy idea, but if it could be implemented, it would be really user-friendly ... and EASY for me :wink:

1 Like

Hi @Mick,

We're aware that JavaScript can be too technical for many users, so we're looking into adding special UI elements to configure such custom logic without any code at all. There is no timeline yet, but it's one of our priorities.

Thanks for the idea! I'll relay it to the dev team.

1 Like

I think that most users have the same concerns and want to solve them as simply as possible. For those who want more, there is the option of realizing the requirements with JavaScript.

How often are there updates to Plumsail Forms for Sharepoint?

1 Like