Ability to Check In 1 or more documents from the List/Library Control

Use Case: Create a button that allows user to checkin one or more documents that have been selected. No need for comments, etc. just checkin documents selected. Code below is pretty much a cut/paste from an example, with the checkin() method,

The function noItemSelected (); calls a dialog asking the user to select an item so we can proceed.

var listOrLibrary = 'LibraryLibrary';
var docLibraryTitle = 'Library';
const checkIn = {
icon: 'AccessibiltyChecker',
class: 'btn-outline-primary',
text: 'Check Document(s) In',
visible: true,
click: function() {
const items = fd.control('LibraryLibrary').selectedItems;
if(items.length == 0){
noItemSelected ();
} else {
function(items) {
var library = pnp.sp.web.lists.getByTitle(docLibraryTitle);
library.getListItemEntityTypeFullName().then(function(entityTypeFullName){
for(var i = 0; i < items.length; i++){
library.items.getById(items[i]).checkin();
}
});
}
}
}
}

fd.control('LibraryLibrary').ready(function(dt) {
     dt.buttons.push(checkIn);
});

POSSIBLE ERROR:
a) Use of function(items)
b) library.items.getById(items[i]).checkin();

There is a syntax type error,. or more, in here somewhere since the entire JS file fails when this code in injected into the form.

Hello @vhancock,

Please test this code:

const checkIn = {
    icon: 'AccessibiltyChecker',
    class: 'btn-outline-primary',
    text: 'Check Document(s) In',
    visible: true,
    click: function() {
        let items = fd.control('ListOrLibrary0').selectedItems;
        if (items.length == 0) {
            //noItemSelected ();
        } else {
            for (var i = 0; i < items.length; i++) {
                pnp.sp.web.getFileByServerRelativePath(items[i].FileRef).checkin()
            }
        }
    }
}
fd.control('ListOrLibrary0').ready(function(dt) {
    dt.buttons.push(checkIn);
});

Thank you. That worked perfectly. Really appreciated.

1 Like