Hi there,
I’m working on a POC using team Forms.
I try to get a single value of a sharepoint list by addind a filter options on a « sharepoint Data Component » :
My items list is filtered and I’m quite happy. But in fact, I want to select the first value of the list as a default value…
I try to modify the « calculated value » as below :
So my question : How can I calculate in a TEXT FIELD or select the first item of a filtered sharepoint data component ?
Thank you for support !
Hi Hugues,
I'll just preface this by saying that this can get quite complicated because the values in the drop-down menu are not calculated until the user opens the drop-down menu. Therefore, you will actually need to perform the same logic/filtering in your text field that would normally be handled by the SharePoint Data component.
Your can automatically set the value of a text field to what would be the first item of your SharePoint data (drop-down) component using the steps below:
Drag-n-drop a text field into your form
In the calculated value of the text field add the following JavaScript. Remember you will need to modify this for your specific forms and filters.
async function getFirstItem(){ const allRows = await tf.getDataSource('insertDataSourceId') const filteredRows = allRows.filter(row => (row?.Title === 'Mr')) // Apply your own filter here return filteredRows?.[0]?.ColumnName } value = getFirstItem()
Hi Hugues,
I'll just preface this by saying that this can get quite complicated because the values in the drop-down menu are not calculated until the user opens the drop-down menu. Therefore, you will actually need to perform the same logic/filtering in your text field that would normally be handled by the SharePoint Data component.
Your can automatically set the value of a text field to what would be the first item of your SharePoint data (drop-down) component using the steps below:
Drag-n-drop a text field into your form
In the calculated value of the text field add the following JavaScript. Remember you will need to modify this for your specific forms and filters.
async function getFirstItem(){ const allRows = await tf.getDataSource('insertDataSourceId') const filteredRows = allRows.filter(row => (row?.Title === 'Mr')) // Apply your own filter here return filteredRows?.[0]?.ColumnName } value = getFirstItem()