Why is my Reopen incident UI action working correctly in the backend, but not in the Employee Porta?

Linda6
Mega Guru

Dear Community,

I'm turning to you for advice. I am supposed to modify the Reopen incident UI action in a way that once the user clicks on it, the incident's assigned to field becomes empty and the state goes to 'New' (and not In progress, as it is set OotB).

 

Now, when doing this in the backend, it works correctly:

incbackend.png

 

However, in the portal view, the state still changes to 'In progress', and I have no idea WHY??

I checked if there are any business rules that may cause this, but nope.

Portal:

incfrontend.png

 

The UI action's script:

// Client side onclick function
function reopenIncident() {
    if (g_form.getValue('comments') === '') {
        // Remove any existing field message, set comments mandatory, and show a new field message
        try {
            g_form.hideFieldMsg('comments');
        } catch (e) {}
        g_form.setMandatory('comments', true);
        g_form.showFieldMsg('comments', getMessage('Please enter a comment when reopening an Incident'), 'error');
        return false; // Abort submission
    }

    // Get the current incident state value
    var currentState = g_form.getValue('state');

    // Check if the incident is in the "Resolved" state (state value of '6')
    if (currentState === '6') {
        // Set the incident state to "New" (state value of '1')
        g_form.setValue('incident_state', '1');

        // Clear the assigned to field
        g_form.setValue('assigned_to', '');

        // Retrieve the current assignment group value
        var assignmentGroup = g_form.getValue('assignment_group');

        // Set the assignment group field value (since it should not change)
        g_form.setValue('assignment_group', assignmentGroup);

        // Submit the form to save the changes
        g_form.submit();
    } else {
        // Display an error message if the incident is not in the "Resolved" state
        alert('This action is only applicable when the incident is in the "Resolved" state.');
    }
}

// Code that runs without 'onclick'
// Ensure call to server side function with no browser errors
if (typeof window == 'undefined')
    serverReopen();

function serverReopen() {
    // Set Incident state to active, update and reload the record
    current.incident_state = 1;
    current.state = 1;
    current.assigned_to = '';
    current.update();
    gs.addInfoMessage(gs.getMessage("Incident reopened"));
    action.setRedirectURL(current);
}

Can anyone please tell me, what I did wrong...? Thank you very much in advance...

 

0 REPLIES 0