I am building an application web form, I have created a choice field that will have the application status (Approved, denied, Under review, etc) and I would like to add a custom JavaScript code to update to a different value after the users click in submit button (final step) in the multi-step form, checking MS documentation https://learn.microsoft.com/en-us/power-pages/configure/add-custom-javascript but not sure who to do it in my case, any recommendations on who may I write this code? below you have an example of what I have tried with no success.
Thank you
if (window.jQuery) {
(function ($) {
if (typeof (entityFormClientValidate) != 'undefined') {
var originalValidationFunction = entityFormClientValidate;
if (originalValidationFunction && typeof (originalValidationFunction) == "function") {
entityFormClientValidate = function() {
originalValidationFunction.apply(this, arguments);
// do your custom validation here
// return false; // to prevent the form submit you need to return false
// end custom validation.
$('#lts_applicationstatus').val(857230001);
return true;
};
}
}
}(window.jQuery));
}
Is this a standard web in at the end of the multistep form? Do you just want to set the value of the choice field as part of the submit?
You could add an event listener to the submit button of the form, you'd have to check that you're on the right step (last step?) then you can make an ajax call to the portal web api to set the field value to the required value.
I wouldn't recommend this personally as it seems this state is some sort of approval process. Doing it from the client side could mean the user could set the state to what ever they want, its not very secure.
I'd recommend setting the approval data on the CRM side using powerautomate, workflow etc. Unless you need the portal user to see the change of state right way. Since any change you make outside of the portal web api won't be reflected in the portal cache until the cache refreshes.