Updating list or library items dynamically

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.

Hello @Arnaud,

It's not that easy.

Since List or Library uses another list, you need to send requests to the other list to update items.

Please see the example in the 'Update uploaded files (List or Library)' article.

Also, doing it on Title update is not the best option, as it will send many requests. Better use a button for this.

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.

@Arnaud,

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;
    image

  • 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;

});

Thank you. I was hoping to get everything done inline, but my users can live with an extra dialog if it means I can pre-fill and filter fields. :slight_smile:

1 Like

Please find more detailed instruction on populating fields in a dialog in the 'Passing values from a parent form to a child opened in a dialog' article.

Now you can manipulate fields within List or Library control in Inline editing mode:

  • populate fields of a new row;
  • populating fields based on other fields in List or Library control;
  • Filtering lookup fields in List or Library control

Please find more details and instructions in the article here.

1 Like