I had to roll out SharePoint autofill column prompts
to about 170 columns across 20 sites, all by script. Surprisingly, it was not straightforward. Writing the prompt
is the easy part, but a prompt set by script does nothing until autofill is switched on, and the calls that switch
it on are not documented anywhere I could find. I worked them out by watching the browser’s developer tools while
saving a column’s autofill settings, then repeated those calls from PowerShell.
Here are the exact steps, with no clicks in the UI.
Column with an Autofill prompt
All samples use PnP.PowerShell and assume you are connected to the site:
Autofill runs when a file is uploaded. Files that were in the library before autofill was switched on (migrated
content, for example) stay empty, and so do files uploaded before you changed a prompt. Nothing in the library
will go back and process them.
To get values on those files, you add each one to autofill’s processing queue: a POST to
/_api/machinelearning/workItems with the file’s ID tells the service “run the prompts on this file”. The
service picks it up within a minute or so and writes the values, exactly as if the file had just been uploaded.
One request per file:
After you add the prompt, the column looks ready: the toggle in the column settings shows On and the column
header has the sparkle icon. But uploaded files never get a value. The toggle only reads IsEnabled from the JSON
above. The autofill service that actually reads documents and writes values keeps its own record of which
libraries and columns are switched on, and adding the prompt does not update it. The /_api/machinelearning calls
in “To switch autofill on” do. They are the same calls the page sends when you save a column’s autofill settings
in the UI, captured from the browser.
In a scored test of 61 documents against two long choice columns, the model returned no values outside the list
once the list was in the prompt. The one problem was the author company: the model added it to 40 of 61 documents,
because its name is on every page. Leaving it out of {{VALUES}} and naming it in the prompt fixed that.
Generating {{VALUES}} from the column keeps the prompt and the choices in sync when someone adds a choice later.
Autofill is billed per page processed, including every queued file. Skip files whose columns already have values.
Autofill does not change Modified or Modified By, and it does not create a new version. The values are
written into the current version: a file uploaded as 1.0 stays at 1.0, with the autofilled values and a
Processed time a minute after Modified.
When migrating content into a library, switch autofill on after the migration, or every copied file is
processed, and billed, on arrival.