With [[@SelectedItems]] placeholder available in Current list execution context of List Actions you can configure Generate document action that generates one document based on metadata of selected items in modern SharePoint list view.
Configuration steps:
List Action
Visible expression:
=[[@SelectedItems]].length > 0
Actions
An example of Word document template (download)
Snippet for “Execute script - Create CAML”:
var caml = '<View><Query><OrderBy></OrderBy><Where><In><FieldRef Name="ID" /><Values>';
[[@SelectedItems.ID]].forEach(function(itemID) {
caml +='<Value Type="Number">'+itemID+'</Value>';
});
caml += '</Values></In></Where></Query></View>';
return caml;
Result:
The result of generated document based on selected items.