DynCon365 / SharePointDragAndDropPCF

A PCF control to drag and drop files to SharePoint libraries.
MIT License
8 stars 4 forks source link

onChange event #8

Open brooza opened 1 year ago

brooza commented 1 year ago

The control is working and seems to be very useful for me. But I am missing any possibility to trigger an onChange event after the upload. E.g. I would like to update the field with document counter or a subgrid showing the uploaded documents. If the control allows this, please share the way how could I trigger it. Thank you very much and have a nice day.

billwinderincremental commented 1 year ago

I had a similar requirement, I had to refresh a documents subgrid when a file was uploaded to the drag and drop control.

I achieved this by making changes to the SharePointUploadControlVM.ts file, at the bottom of the function "onFileDropped", you can force a change to the bound field. The example below triggers the field to be set to a random number, although you could use something else (eg a date time or something, just anything to change the field)

let r = (Math.random() + 1).toString(36).substring(7);
let controls = this.controlContext.setParameters(
  {
    boundEntityField: r
  }
);

On the CRM form itself you can then put an onchange event on the bound field, the example below reloads the subgrid and saves the form.

function nameChange(executionContext) { var formContext = executionContext.getFormContext();
formContext.getControl("Subgrid_new_1").refresh(); formContext.data.save(); }

PowellPowell commented 11 months ago

@billwinderincremental thanks! This is exactly what I was looking for. I have currently solved this by running Xrm.Page.getControl(‘subgrid’).refresh() directly from the PCF code. But as this is not supported and Xrm.Page is deprecated, your solution is the one 😄👍🏼