Hey everyone, I've combed through examples and documentation but I can't seem to get this to work.
I'm trying to set the title of children items based on the title of the current item. Pretty simple stuff. Here's my code:
fd.spRendered(function() {
function setChildTitle() {
var items = fd.control('SPDataTable1').widget.dataItems();
if(items){
for (var i = 0; i < items.length; i++){
if(items[i].Title)
items[i].set("Title",fd.field('Title').value + '-' + i);
}
}
}
// Update children when the user changes the PO number
fd.field('Title').$on('change',setChildTitle);
// Update children when the user adds a record
fd.control('SPDataTable1').$on('change',setChildTitle);
});
The changes appear correctly in the form when the Title field is updated, but the changes don't appear to trickle down to the child list. The change also doesn't appear to work for child items being added.
Thank you for pointing me in the right direction. Maybe I'm going about this wrong, but since the children title field is set to require unique values in sharepoint, I can't set it after creation using a pnp command. I was hoping to intercept the List or Library object before creation to avoid that issue.
You can pass value from the parent form to child if the child item is opened in the dialog. Please follow the below steps:
Please define fd globally in the parent Form by pasting the code window.fd = fd; in Javascript Editor;
Please paste the below code in Javascript Editor in the child Form. Replace filed names in the code with the internal names of the field from your form.
fd.spRendered(function() {
//Set field value with the value from the parent on form load
fd.field('ChildFieldInternalName').value = window.top.fd.field('ParentFieldInternalName').value;
});