Setting Value of Lookup Field

I have 3 Fields on a Form (LineOfBusiness, Category, and Type). All three are Lookup Controls to Lists in a different site.

I have Category Defined as Depends on LineOfBusiness, and Type Depends on Category.

The fields work Great....until I do the following code:

fd.control('LineOfBusiness').value = 5;

The LineOfBusiness field populates as expected, however, the Category Field does not filter to the Categories for that Line of Business, There are no choices available. The field only populates with choices when I manually change the LineOfBusiness control.

Hello @sphilson,

How the filter is set up? Please share the screenshot of the filter section from the designer and specify columns types in the Match to property.

Hello @sphilson,

You can set control value programmatically and keeping filtration using this code:

fd.control('LineOfBusiness').value = {ID: 2, LookupId: 2}
1 Like

That worked!!!! Thank you!

1 Like

@Margo
hello,
i have sharepoint 2019, i tried ti set lookup by:
fd.control('LineOfBusiness').value = {ID: 2, LookupId: 2}
it put value, but when i want to get extra fields it can't be done. how to refresh this lookup? or to apply value to get extra fields?
i want set by code a lookup value, and auto populate other fields with extra fields from lookup

@ixxxl,

You can use this code in SharePoint 2019 to set the lookup control value and get extra field value:

fd.control('Lookup1').value =  2;
fd.control('Lookup1').reloadValue();
var extraFieldValue = fd.control('Lookup1').value.ExtraFieldName

@Margo
i tried, but have error
image

	// var cod= fd.field('TextBox6').value
	fd.field('Subdiviuni').value =  242;
  fd.field('Subdiviuni').reloadValue();

			 alert('start') 
		//fd.field('Subdiviuni').value = {ID: 242, LookupId: 242, LookupText: "HR"}
		 fd.field('Subdiviuni').ready().then(function (field){
		
	//	 var us = fd.field('Subdiviuni').value.Manager_x0020_conform_x0020_Func
	//	 alert(us)

		
 //fd.field('User').value=us
var selected = fd.field('Subdiviuni').value.Manager_x0020_Notificare; 
var s = '';
for (var i = 0; i < selected.length; i++) {
    s += selected[i].Name + '; ';
	alert('s=   '+s)
	 fd.field('User2').value=s
}
		 });

@ixxxl,

What version of the designer are you using? Please make sure you are using the latest version v1.8.7.

Also, you can get other column values using PnPjs requests.

@Margo
1.4.8 designer version.
i see that there is a new version. i must to update it in app catalog? will it affect to pervious our forms ? after update designer i must to publish all my forms ?

For example from manual:
--Separate forms are not generated anymore for every form set. A default form resolves the form set now.

i have many forms with different form sets, what will be with them after update ? i must recreate form?

In my experience, when upgrading (especially one of the more recent upgrades) I had to republish all of my forms and in the process had to check some of the form panel settings before I published.

@ixxxl,

You can find instruction on updating Plumsail Forms On-Premises solution here.

After the update forms sets and routing should work without re-saving forms. But in case of any issues re-saving of the form will help.

Hi @Margo I have a lookup field that depends on a choice field. I am trying to set the default value of the lookup field but it remains blank. Any suggestions?

Thanks.

Hello @aseem,

You need to set the default value for the Choice field too. Please try it out.

Try this...

fd.field('Subdiviuni').reloadValue().then(() => {
//Not sure why you are doing this. unless you are expecting an multiple managers back, and even then, this loop feels incorrect
//var selected = fd.field('Subdiviuni').value.Manager_x0020_Notificare; 
//var s = []; //made this an array. 
//for (var i = 0; i < selected.length; i++) {
//    s.push( {Id: selected[i].Id, LookupId: selected[i].Id Value: selected[i].Name });
//    alert(s);
//}
fd.field('User2').value = {
  Id: fd.field('Subdiviuni').value.Manager_x0020_Notificare.Id, 
  LookupId: fd.field('Subdiviuni').value.Manager_x0020_Notificare;.Id, 
  Value: fd.field('Subdiviuni').value.Manager_x0020_Notificare;.Name };

fd.field('User2').reloadValue();
});

This makes sure the code doesn't execute until after the reload of the field Subdiviuni reload completes, so your extra field will be loaded.