Populate fileds from parrent form in child dialog list and library control

Good day!
@mnikitina
I'am trying to populate child field in dialog of list and library control by parent field value.
i was using manual https://plumsail.com/docs/forms-sp/how-to/pass-values.html
but I have error


I have in parrent form field category which is a lookup pointing to list categories.
in child diaolog form i have field cat (multiple line)

fd.spRendered(function() {
    var parentForm = window.top.fd;

    if (parentForm) {

        //Set field values with the values from the parent on form load
        fd.field('cat').value = parentForm.field('Categorii_x0020_de_x0020_adresa_0').value;
       
        //Disable Location field
        fd.field('cat').disabled = true;
    }
});

Hello @ixxxl,

What is the type of the Categorii_x0020_de_x0020_adresa_0 field? Is it a multiple choice lookup field?

@mnikitina
Categorii_x0020_de_x0020_adresa_0 - yes, It is multiple lookup pointing to list of categories.

Hello @ixxxl,

Since this is a multiple-choice search box, the value is an array of objects. To get the selected values ​​as a string you need to access each object. You can find more information on how to work with the lookup fields in our documentation here.

 fd.spRendered(function() {
    var parentForm = window.top.fd;

    if (parentForm) {
        var selected = parentForm.field('Categorii_x0020_de_x0020_adresa_0').value;
        var s = '';
        for (var i = 0; i < selected.length; i++) {
            s += selected[i].LookupValue + '; ';
        }
        //Set field values with the values from the parent on form load
        fd.field('cat').value = s;
       
        //Disable Location field
        fd.field('cat').disabled = true;
    }
});
1 Like

@mnikitina
Thank you so much, it works perfect!

1 Like

@mnikitina
One more question.
If i have:

  1. parent form
  2. child dialog form 1 from parent.
  3. child dialog form #2 ( from child 1)
    How to get data for example form 1 to 3(from parent to child 2) . Or from 2 to 3 (from child1 to child2)?

I tried the code, but it returns nothing....

Hello @ixxxl,

Using this approach you will always get field values from the topmost window.

You can save values of child dialog 2 to local storage to pass them to child dialog 3. Please find more information about the local storage object here.

Hi, @mnikitina
I just tried to do in parent form from which i want to store filed value

     fd.spRendered(function () {
                function Store() {
            if (typeof(Storage) !== "undefined") {
      // Code for localStorage/sessionStorage.
      localStorage.lastname = fd.field('Categorii_x0020_de_x0020_adresa_').value;
    } else {
      // Sorry! No Web Storage support..
      alert('error');
    }
}
fd.field('Categorii_x0020_de_x0020_adresa_').$on('change', Store);

    });

And in dialog form to which i want to retrieve field value

fd.spRendered(function () {
function setFieldPropreties() {
      
		if (typeof(Storage) !== "undefined") {
  // Code for localStorage/sessionStorage.
  document.getElementById("cat").innerHTML = localStorage.lastname
} else {
  // Sorry! No Web Storage support..
  alert('error');
    }
    // executes setFieldPropreties on form load
    setFieldPropreties();
});

Is it correct? it doesn't work....

in browser console i found that my multiple lookup fd.field('Categorii_x0020_de_x0020_adresa_').value; returns:
image
I tried with the text one it works good. But still problem with retrieve in dialog child form

In child dialog box i changed code direct to the field. It works.

//old part
 // document.getElementById("result").innerHTML = localStorage.lastname
//new
  fd.field('cat').value = localStorage.lastname

I tried to set value in a text field 'cat' of multiple lookup as soy say previously

 fd.spRendered(function () {
        //get all buttons
        function Store() {
		var selected = field('Categorii_x0020_de_x0020_adresa_').value;
		 var s = '';
        for (var i = 0; i < selected.length; i++) {
            s += selected[i].LookupValue + '; ';
        }
        //Set field values with the values from the parent on form load
        fd.field('cat').value = s;
		
            if (typeof(Storage) !== "undefined") {
      // Code for localStorage/sessionStorage.
     sessionStorage.lastname = fd.field('cat').value;
    } else {
      // Sorry! No Web Storage support..
      alert('Ahtung');
    }
}
fd.field('Categorii_x0020_de_x0020_adresa_').$on('change', Store);

    });

But in console have error
image

One more thing is with multiple fd.field('Categorii_x0020_de_x0020_adresa_').value;

Hello @ixxxl,

There is a syntax error, you are missing fd in this line:

Please correct the error and test the code, it should work:

var selected = fd.field('Categorii_x0020_de_x0020_adresa_').value;
1 Like

@mnikitina
Super!! Thank you!!, now it works!

1 Like

Hi @mnikitina
I put data in people picker field in a new dialog form(from list and library control), from custom text field from user profile.
And want to work with field people picker with people. but at this moment they are as a text. After save this field is good. Is it a way t refresh the field or something else to become as people-users?

p.s. today i was trying to save form,and make redirect to edit. but it closes after save, because it is in dialog window of list and library control of the mai list.

and this one

 fd.field('User').ready().then(function(field) {
        console.log(field.value);
        // or
        console.log(fd.field('User').value);
    });

nothing result

Hello @ixxxl,

User properties are available only when the value is selected manually or data is saved to the SharePoint list.

If you need to get user profile properties, you can use the PnPjs library. Please see the example here.

@mnikitina
yes i use this

function updateUserInfo2() {


	pnp.sp.profiles.myProperties.get().then(function (result) {
		var props = result.UserProfileProperties;
		for (var i = 0; i < props.length; i++) {
			switch (props[i].Key) {
				// Sharepoint or AD attribute  


				case 'bossLevel1':
					//Form Field Internal name
					fd.field('Boss1').value = props[i].Value;
					break;


			}
		}
	});

}



// executes setFieldPropreties on form load

updateUserInfo2();
});

But when i'am in a new form . the field boss1 -have value as a text, and will be a person only after save... is it a way to become as person on load?

@mnikitina
Hi,
Can i close parent form automatically when is closing child form?

I tried to use inline list and library control populate from parent, but it is empty...



fd.spRendered(function() {
    //prepopulating fields of a new record
    //with the values from the parent form
    fd.control('SPDataTable2').$on('edit', function(editData) {
        //check that this is a new record
        if (editData.formType === 'New') {
            //prepopulating due date
			editData.field('Utilizator').value = fd.field('Author').value;
			editData.field('Title').value = fd.field('Title').value
            
           
           
        }
    });
});

Does it works only in Online ? i have On-prem. (see some info about this that's work only in Online)
If so, than i need to close parent form automatically when is closing child form...

Hello @ixxxl,

Why do you need the value to be an object? Do you need to populate manager profile properties?

If so, you can use the same PnPjs request to get the profile properties of the manager.

Yes, the Edit event of a List or Library control is currently only available for the SharePoint Online version.
Could you please provide more details about the case.

Do you want the parent form to be closed when the child item is saved? Or when the dialog with the cold form is closed and the changes are not saved?

@mnikitina

yes, i would like to close parent form when child is saved.

function checkIfBossHasPermission(bossId, groupList) {
	pnp.sp.web.siteUsers.getById(bossId).groups.get()
		.then(function (groupsData) {
			var vb = false;
			var i = 0;
			var s = "";
			var cautaIn = groupList;
			alert("cautaIn="+cautaIn);
			while (vb == false && i < groupsData.length) {
				s = groupsData[i].Title;
				if (cautaIn.search(s) > 0) {
					vb = true;
				} //if
				i++;
			} //while
			return vb;
		}); //then
} //function

//fd.field('Boss1').ready().then(function(field) {
fd.field('Boss1').$on('change', function(value) { 
	var people = field.value;
	var vb=true;
	var s="";
			alert(people.length)
			alert(people)
	for (var i = 0; i < people.length; i++) {
		vb=vb && checkIfBossHasPermission(people[i].EntityData.SPUserID, sessionStorage.lastname);
		s+people[i].DisplayText + " "+vb+" ";
				alert("i="+ i+ " s=" + s);
	}

	fd.field('Permisiune').value=vb;
})

I want to count how many people are in people picker field. And if i have people as a text .. for 3 persons it is 54 symbols, not 3 .

@ixxxl,

You can get the count of selected users using this code:

fd.field('PersonOrGroup').widget.dataSource.data().length
1 Like

Hello,

is it possible to pass the values from parent form to child form only when "new form" ist opened in child list?

Hello @UDRO,

You can add a condition to the code to check that this is a "New" form:

fd.spRendered(function() {
    var parentForm = window.top.fd;

    if (parentForm && fd.formType == 'New') {

        //Set field values with the values from the parent on form load
        fd.field('Facility').value = parentForm.field('Facility').value.ID;
        fd.field('Priority').value = parentForm.field('Priority').value;
        fd.field('AssignedTo').value = parentForm.field('Manager').value;

        //Disable Location field
        fd.field('Facility').disabled = true;
    }
});
1 Like

Hi @mnikitina ..... I have three forms (parent, child 1, subform 2). The last one is a subform to child 1 only, not directly to the parent.

In child 1 form, a person field is entered. I need to pass this value to subform 2.

In child 1 form, I have tried populating a second (single line text field) with the value of the person field using fd.field('persontext').value = fd.field('personfield').value.DisplayText
but the 'persontext' field remains blank. I have added the code to both spSaved and spBeforeSave

In child 1 form, I have also tried to use localstorage:

function setFieldProperties(){
if (typeof (Storage) !== 'undefined){
if(localstorage.personfield) != null){
fd.field('persontext').value = localStorage.personfield;
}
}
}

setFieldProperties();

Neither of these SAVE the value to the single text field ('persontext');

How can I either 1. Get the 'person text' field to save the 'person field' value OR
2. pass the "person field' value to the subform 2?

Thanks, Rhonda