Custom button to change a field and save the form


#1

Dear Plumsail Team,

I am using Plumsail Forms in SharePoint Online. I have 2 custom buttons in the form toolbar, I would like the status of the SharePoint item to be changed to Approved and the item to be saved when the first button is clicked. The logic behind the second button is the same but the new status should be Rejected. I am not able to figure out how to accomplish that. I tried using the save method (in fd.spRendered), register to the spBeforeSave event (in fd.spRendered as part of the toolbar push button code), and added the update logic there:
fd.field(‘Status’).value = “Approved”;
From what I can see, the field on the form is updated but after the save occurs, the new status is not available in the SharePoint item. One assumption is that I have to use the spForm object provided in the spBeforeSave event but I am not sure how to do that.
Could you please advice if I am doing the right thing. A code snippet would be much appreciated!

Kind regards,
Martin


#2

Just a quick update - here is the source code that works in Chrome and Firefox but does NOT work in IE11:

fd.spRendered(function() {

//add submit button to the toolbar
fd.toolbar.buttons.unshift({
    class: 'btn-outline-primary',
    text: 'Submit',
    click: function() {
		
		fd.field('Title').value = 'Strategic Alignment Review';
		
		fd.save();
    }
});

});


#3

It looks kind of timing issue - if I plug a js alert between
fd.field(‘Title’).value = ‘Strategic Alignment Review’;
and
fd.save();
then it works in IE11 as well. Which probably brings us back to the topic of how to use the spBeforeSave event.


#4

Hi Martin, this looks very similar to the issue I’m having with the spBeforeSave handler - see this post:

I seem to get a similar thing with a Title field I’m updating in my form - thought I’d link this up just in case any admins are looking at these two separate items, I think Alex Zverey is looking at the issue.


#5

Thanks, Andy! In my case, in order to work properly in IE11, I had to add a minor delay between the field update and the save operations. It’s not ideal, I know.

Here is the source code (the button is part of the toolbar):
fd.spRendered(function() {

//add reject button to the toolbar
fd.toolbar.buttons.unshift({
    class: 'btn-outline-primary',
    text: 'Reject',
    click: function() {

		fd.field('Status').value = 'Rejected';
		setTimeout(function(){
			fd.save();
		}, 300);
    }
});

});


#6

Dear @abolam, @mkaraivanov,

The issues are very similar and appeared to happen only in IE, we are researching them.


#7

I can report that I have this issue in Chrome, Firefox and Edge, so perhaps my issue is different? Regardless of browser, the spBeforeSave handler appears to revert any of my updates to the default value in the Title field. I will try a straightforward, non-PnP update and see if this is any different, to establish if the issue is due to the asynchronous operation.


#8

Dear @abolam,

I’ve slightly changed the code, please check it out! Default Column Value not appearing in Form, and unable to run Async PnP in BeforeSave