Add extra button to toolbar (Submit) and change a choice field on click/save

Hi there, I'm just having trouble with the JS to add a button and change a choice field.
Button is Submit for Draft Approval, action is change the choice field 'Status' to 'Draft'. The button show up, I'm clicking and nothing is happening. I've updated the 'Save' button to be, 'Save Changes' as the key button needs to be this submit buton.... Please help.

fd.spRendered(function() {

//add submit button to the toolbar
fd.toolbar.buttons.unshift({
class: 'btn-warning',
text: 'Submit for Draft Approval',
location: 0,
click: function() {
fd.field('Status').value('Draft');
fd.save();

image

Dear @Nicola_01,
The value is not set this way. It should be like this:

fd.spRendered(function() {
    var draftBtn = {
        class: 'btn-warning',
        text: 'Submit for Draft Approval',
        location: 0,
        click: function() {
            fd.field('Status').value = 'Draft';
            fd.save();
        }
    }

    //add new button
    fd.toolbar.buttons.unshift(draftBtn);
});

Thanks, I have done that which has added the button. However, pressing the button does not do anything. It just stays on the form, doesn't save....

Dear @Nicola_01,
Check console for errors when clicking the button. Most likely there is an error, for example, you don't have a Status field, or this field has a different Internal Name.

Got it, thanks again!!!

One more thing. I'm wanting to a confirm message 'Are you sure you want to submit this form' and also have the value set on save as above. But having trouble. This I am using to start a Powe Automate workflow. Or maybe I've gone about it the wrong way....

fd.spRendered(function() {
    var draftBtn = {
        class: 'btn-warning',
        text: 'Submit for Draft Approval',
        location: 0,
        click: function() {
            fd.field('Status').value = 'Draft';
            if (confirm('Are you sure you want to submit the form?')) {
            fd.save();
        }
    }

    //add new button
    fd.toolbar.buttons.unshift(draftBtn);
});

Dear @Nicola_01,
Everything seems correct, but you seem to be missing a bracket, here:

fd.spRendered(function() {
    var draftBtn = {
        class: 'btn-warning',
        text: 'Submit for Draft Approval',
        location: 0,
        click: function() {
            fd.field('Status').value = 'Draft';
            if (confirm('Are you sure you want to submit the form?')) {
                fd.save();
            }
        }
    }

    //add new button
    fd.toolbar.buttons.unshift(draftBtn);
});

Ahhhhh, always something little. Thanks so much!!!!

1 Like