0

I am using the PnP DateTimePicker web part in SPFx, and the following code works great. When I select a new date in the DateTimePicker, it saves the date to a SharePoint list. However, every time I do this, a new row is created. How can I update the existing row instead of creating a new one?

import * as React from 'react'; import styles from './PnpDatePicker.module.scss'; import type { IPnpDatePickerProps } from './IPnpDatePickerProps'; import {DateConvention, DateTimePicker} from "@pnp/spfx-controls-react/lib/DateTimePicker" import { DayOfWeek } from '@fluentui/react'; export default class PnpDatePicker extends React.Component<IPnpDatePickerProps> { public render(): React.ReactElement<IPnpDatePickerProps> { return ( <div className={styles.pnpDatePicker}> <DateTimePicker label="Datumfilter" dateConvention={DateConvention.Date} formatDate={(date: Date) => date.toLocaleDateString()} firstDayOfWeek={DayOfWeek.Monday} isMonthPickerVisible={false} onChange={this.handleChanged} ></DateTimePicker> </div> ); } public async handleChanged(date:any) { await sp.web.lists.getByTitle("DatePicker").items.add({ 'CustomDate':date} ) } } 

1 Answer 1

1

If you know the item ID of SharePoint list item which you want to update, you can use code like below:

public async handleChanged(date:any) { await sp.web.lists.getByTitle("DatePicker").items.getById(1).update( { 'CustomDate':date } ) } 

Where 1 is the SharePoint list item ID.

References:

  1. @pnp/sp/items - update items.
  2. PnP DateTimePicker in the SharePoint Framework (SPFx) webpart.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.