Page 1 of 1

Document check-in on submit

Posted: 30 Oct 2020
by cmagnan
Hi,
Is there a way to check-in the document on submit function?

fd.onsubmit(function(){
if(!error){
fd.field('Test').value('Yes');
return true;
}
else{
alert("Error.");
}
});

Thanks

Re: Document check-in on submit

Posted: 04 Nov 2020
by mnikitina
Hello cmagnan,

You can create a flow that starts on item submission and check-in/check-out the document.

Re: Document check-in on submit

Posted: 04 Nov 2020
by cmagnan
Hello mnikitina,

Hi have already a workflow start after a modification, the first step of the workflow is to wait the check-in of the document.

So when the Test field value will be set to Yes on submit, I want also to check-in the document.

Is it possible?

Thanks

Re: Document check-in on submit

Posted: 09 Nov 2020
by Nikita Kurguzov
Dear @cmagnan,
It wouldn't work in onsubmit, as it takes time to process a request, but you can make sure the file is checked in and then saved:

Code: Select all

var itemId = fd.getUrlParam(window.location.href, 'ID');  
var targetListItem;

function runCode() {
   var clientContext = new SP.ClientContext.get_current();
   var targetList = clientContext.get_web().get_lists().getByTitle('Documents');
   targetListItem = targetList.getItemById(itemId);
   clientContext.load(targetListItem, 'FileLeafRef');
   clientContext.executeQueryAsync(function(){
     var oFile = targetListItem.get_file();
     console.log(oFile);
     oFile.checkIn();
	 clientContext.executeQueryAsync(function(){
		fd.save().click();
     }, function(sender, args){
	    alert('Failed! ' + args.get_message()); 
	 });
   });
 }

runCode();
There is a problem with this method though... The changes on the form are not applied before save, so if required fields are filled in on the form - they'll be missing, and the save is not triggered before check-in - it's a catch-22.

You can try to remedy it, by setting required fields manually. For example, here I am setting fields Title and Date manually:

Code: Select all

var itemId = fd.getUrlParam(window.location.href, 'ID');  
var targetListItem;

function runCode() {
   var clientContext = new SP.ClientContext.get_current();
   var targetList = clientContext.get_web().get_lists().getByTitle('Documents');
   targetListItem = targetList.getItemById(itemId);
   clientContext.load(targetListItem, 'FileLeafRef', 'Title','Date','DateTime');
   clientContext.executeQueryAsync(function(){
     targetListItem.set_item('Title', fd.field('Title').value());
     var dateString = fd.field('Date').value();
     var dateParts = dateString.split(".");
     var dateObject = new Date(+dateParts[2], dateParts[1] - 1, +dateParts[0]); 
     targetListItem.set_item('Date', dateObject);
     targetListItem.update();
	 clientContext.executeQueryAsync(function(){
	 	var oFile = targetListItem.get_file();
	    console.log(oFile);
	    oFile.checkIn();
		clientContext.executeQueryAsync(function(){
			fd.save().click();
	    }, function(sender, args){
		   alert('Failed! ' + args.get_message());
		});
     }, function(sender, args){
	    alert('Failed! ' + args.get_message());
	 });
   });
 }

runCode();
This, on the other hand will give you a message that the item has been modified when you try to save:
FileModified.png
FileModified.png (17.26 KiB) Viewed 8804 times

Document check in on submit

Posted: 21 Nov 2020
by JacksonPsynC
I'm using the new cache submission page and the only way to submit a cache listing for review is to check off the "Yes, the cache is in place and ready to be found" checkbox.

How do I submit a coordinate check without enabling that checkbox?

Just enable the listing with a note to the reviewer indicating I am checking if the location is free?

Re: Document check-in on submit

Posted: 30 Nov 2020
by Nikita Kurguzov
Dear JacksonPsynC,
Unfortunately, I am not sure what you mean. Are you using Forms Designer for this? Can you attach some screenshots that would showcase the process, and also what exactly you want to achieve?