Document check-in on submit

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

30 Oct 2020

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

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

04 Nov 2020

Hello cmagnan,

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

cmagnan
Posts: 23
Joined: Fri Jan 26, 2018

04 Nov 2020

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

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

09 Nov 2020

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 12433 times
Cheers

JacksonPsynC
Posts: 2
Joined: Tue Nov 17, 2020

21 Nov 2020

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?

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

30 Nov 2020

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?
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests