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;
}
});
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;
}
});
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:
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
One more thing is with multiple fd.field('Categorii_x0020_de_x0020_adresa_').value;
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);
});
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...
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?
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;
}
});
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?