Copying data from Text field to Person or Group field

I have a form that uses some Lookup lists to allow you to select the approver for the form based on a few selections. The issue I am running into is I am only able to use a Lookup field for Text fields and not People or Group fields.

I am using this list to determine which approver should be selectable in the form based on the budget code that was selected. I got that to work, but I can only select the Title column for the lookup field since that is a Text field, when I want the data in the Approver column since it is a Person or Group field. The Title and Approver field have the same text in each row, but the Title field is a Text field and the Approver field is a Person or Group field.

I was wondering if there was a way to take the data from the Lookup field in the form and get it into a Person or Group field on the form. I need this so I can use the Approver in an email workflow in Power Automate. I want the Approver to receive an email when the form is submitted, but currently I cannot email them through Power Automate since I cannot get the data into a Person or Group field.

Hello @zddummer,

What value is stored in the Title field? Is it approver's name or email?

If it is email, you can populate Person or Group field on the form using the code:

fd.spRendered(function() {
	fd.field('LookupFieldName').$on('change', function(value) {
		fd.field('PersonFieldName').value = value.LookupValue;
	});
});

If it's not, you need to specify the Person or Group column name in the Extra fields and Expand properties like so.

For Extra fields: Person
For Expand: Person/Name

Then on teh form you will be able to populate person field using the code:

fd.spRendered(function() {
	fd.field('LookupFieldName').$on('change', function(value) {
		fd.field('PersonFieldName').value = value.Person.Name;
	});
});

Person is the internal name of the SharePoint column in the source list.
LookupFieldName is the internal name of the Lookup field on the form.
PersonFieldName is the internal name of the Person or Group field on the form.

Another option is to get the Approver email in the Power Automate using the Get Item action.

I am guessing that I am missing something. I am using the first method since the Title field in that list has the approver's email. This is the code I am using:

fd.spRendered(function() {
fd.field('ApproverEmail').$on('change', function(value) {
fd.field('Approver_x0020_ID').value = value.LookupValue;
});
});

This is how it looks on the form:
approverEmail

The ApproverEmail field is a Lookup field that is pulling the email from the Title column in the list. The Approver ID field is a Person or Group field.

It's not auto-populating when I select the approver's email address from the Lookup.

@zddummer,

Please check the browser console(F12) for the errors and share the screenshot.

Here are the error from the form page:



@zddummer,

Please make sure that the ApproverEmail is the internal name of the field and try adding teh ready event like so:

fd.spRendered(function() {
	fd.field('ApproverEmail').ready(function() {
		fd.field('ApproverEmail').$on('change', function(value) {
			fd.field('Approver_x0020_ID').value = value.LookupValue;
		});
	});
});

I tried the code you sent me and double checked that the internal names were correct and it is still not auto-populating in the Approver ID field when I select the email address from the ApproverEmail field.
approverEmail2

@zddummer,

Please export the form and share it with me for testing.

Plumsail Form.json (27.4 KB)

@zddummer,

Thank you!

There seems to be an issue elsewhere in the code, as the code handling the Person or Group data appears to be working correctly. To isolate the problem, please comment out all other code and test only this part:

fd.spRendered(function() {
	fd.field('ApproverEmail').ready(function() {
		fd.field('ApproverEmail').$on('change', function(value) {
			fd.field('Approver_x0020_ID').value = value.LookupValue;
		});
	});
});

I commented out everything except that code and it still did not work. Approver ID field would not autofill. Tried multiple times, but could not get it to work

@zddummer,

I've taken another look at your form, and noticed that the ApproverEmail is not a lookup field, it is a control. Please update the code like so:

fd.spRendered(function() {
	fd.control('ApproverEmail').ready(function() {
		fd.control('ApproverEmail').$on('change', function(value) {
			fd.field('Approver_x0020_ID').value = value.LookupValue;
		});
	});
});

That worked! Thanks so much for your help with this!

1 Like