- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
The problem seems to be that your client code is going into an infinite loop.
If the user provided the close_code and close_notes, state is set to Closed then your script calls the UI action and the same client script gets runned over and over. If one of the two fields is left empty, then it sets the state to closed and returns without mandatory check because it is executed before the onsubmit client scripts.
I'm unsure why you did not use the script I provided (other than replacing the action name).
Here is the use case it covers:
- State not updated both close code and notes are empty: The state is set to closed and record is submitted again which gets blocked by the mandatory fields enforced by UI policy.
- State was manually set to close (or by using the button first): Script does nothing because state is already closed and UI policy are enforced for mandatory fields
- State not updated, close code and notes are filled: The state is set to closed and record is submitted again, because the closure fields are filled, the records passes the mandatory check enforced by UI policy and the script lets the record be submitted.
Your script does not need to check for the close code and close notes to not be empty since it will be handled by the UI policies in place.
If you don't want to use the UI policies, you could simply set the fields as mandatory and not touch the state (it will be handled by the server script you provided). Something like:
function onSubmit() {
if (g_form.getActionName() != 'sp_close_change') {
return;
}
if (g_form.getValue('close_code') == '' || g_form.getValue('close_notes') == '') {
g_form.setMandatory('close_code', true);
g_form.setMandatory('close_notes', true);
g_form.submit(g_form.getActionName());
}
}