Hi,
I'm allowing users to check in and out from the form via PnP JS and buttons.
It's coming together, except for discarding a checkout. This is the button Click event script:
var FileLeafRef = fd.field('FileLeafRef').value;
var ServerRelativeUrl = "/sites/StartCardsandSWMS/SWMS/" + FileLeafRef
sp.web.getFileByServerRelativeUrl(ServerRelativeUrl).checkin("Overwritten", CheckinType.Overwrite).then(() => alert("Discarded"))
.then((response) => { return response; }).catch((e) => { alert("Discard Check Out Failed, either you don't have permission or it's already discarded"); });
The issue I'm having is that CheckinType is not available...
How would I:
import pnp, { CheckinType } from "sp-pnp-js" ?
You guys have amazing support! I hope this one is easy and doable, my users struggle with OOTB and love buttons.
Thanks!
Hello @AdamSmith,
Please try out the following code:
var FileLeafRef = fd.field('FileLeafRef').value;
var ServerRelativeUrl = "/sites/StartCardsandSWMS/SWMS/" + FileLeafRef
pnp.sp.web.getFileByServerRelativeUrl(ServerRelativeUrl ).checkin('Overwritten', 2).then(function(){
alert('Overwritten')
});
Where:
2 - overwrite the file;
1 - incremented as a major version;
0 - incremented as a minor version
Nice that allows the request to go through, but returns a 500 error for overwrite.
I can check a file out.
I can check in a minor version.
I can check in a major version.
Which is all great.
This works:
var FileLeafRef = fd.field('FileLeafRef').value;
var ServerRelativeUrl = "/sites/StartCardsandSWMS/SWMS/" + FileLeafRef
var PublishComment = fd.field('VersionComment').value;
pnp.sp.web.getFileByServerRelativeUrl(ServerRelativeUrl).checkin(PublishComment, 1).then(() => alert("Published and file Checked In"))
.then((response) => { return response; }).catch((e) => { alert("Publish Failed, either you don't have permission, it's already published, or you didn't provide a comment."); });
but, this does not:
var FileLeafRef = fd.field('FileLeafRef').value;
var ServerRelativeUrl = "/sites/StartCardsandSWMS/SWMS/" + FileLeafRef
pnp.sp.web.getFileByServerRelativeUrl(ServerRelativeUrl).checkin('Discard', 2).then(() => alert("Discarded"))
.then((response) => { return response; }).catch((e) => { alert("Discard Failed, either you don't have permission, it's already discarded, or you never had it checked out."); });
Returns a 500 error:
These are the library settings:
I'm thinking this is an issue outside of Plumsail's control, maybe?
I can probably execute a discard checkout flow from a custom row action within the library.
Which might actually work better...
It would be pretty handy to have a discard checkout button though.
Is there something else I should try?
Thanks
Hello @AdamSmith,
Overwriting does not seem to work if you allow the creation of major and minor versions. Try changing the settings to allow only major versions to be created, and test the code.
Yes, it works when only major versions are created.
I'd be tempted to raise an issue in the PnP JS repo.
So, I need to make a decision.
-
Have no drafts, but get discard checkout button.
-
Have drafts, but discard is done via flow.
I think I'll try a flow.
If there is anything else you can suggest or try that would be appreciated.
I'm still declaring success, can't have them all. Or can we? No, probably not...
Hello @AdamSmith,
I couldn't check in the file with the flow when minor and major versioning is enabled.
So I think this is a SharePoint library limitation.
1 Like
Flow worked. Thank you for your assistance!
1 Like