Custom submit button doesn't save field value

In an approval workflow I want to set the button text dynamically and set the ‘Stage’ field value depending on the stage I am advancing to:
var stage = fd.field(‘Stage’).value;
switch(stage) {
case ‘Define’:
fd.control(‘Submit’).onclick = ‘fd.field(“Stage”).value = “Research”;fd.save();’;
break;
case ‘Research’:
fd.control(‘Submit’).onclick = ‘fd.field(“Stage”).value = “Conceptualization”;fd.save();’;
break;
case ‘Conceptualization’:
fd.control(‘Submit’).onclick = ‘fd.field(“Stage”).value = “Execution”;fd.save();’;
}

I read the posts on Set Value and then Save
Custom button to change a field and save the form
and ’ Default Column Value not appearing in Form, and unable to run Async PnP in BeforeSave

Tried to do that in spBeforeSave but still no luck.

Any help would be great!

Hi jmarciniak,

Your jQuery is missing a .click() to action the saving of the item.

use fd.save().click();

:slight_smile:

I just tried that but still doesn’t work.
It seems to throw an error now in the console when I click the button, but it disappears quick and navigates back to the list, so I don’t know what this would be about.

Best regards,

Jakub

Dear Jakub,

Please try to add the “debugger;” command into your code and open the form with the browser console (this command will stop your code). Provide us, please, the screenshot of the error.