UI Action error: Unchanged ReferenceError: current is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:06 AM - edited 10-03-2023 11:33 AM
Hi all, I am having trouble with a line of code. Please not this works beautifully on the form but when I try to run ATF, I get the error
Please see code below
Please see error
Anyone know what is causing this and step on how to fix.
Please Note: This is happening on the browser console and not the front end

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:19 AM
Hey Malo,
UI Actions are odd. They can do both server and client side stuff, but your code is all running client side. `current` is a special object servicenow uses that isn't available on the client on line 25 you have code that says hey does window exist? if so do tis server call on line 26. That's one way to handle this.
Let me know what you tried and if it worked. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:22 AM
Hi @Malo ,
Remove 11 th line of code, copy and cut the 12 th line and paste after 15 th line.
Add below code after your 4rth line of code.
gsftSubmit(null, g_form.getFormElement(), 'action_name');
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:59 AM
This is very similar to an issue I am seeing on our instance. I am lost here and hoping you all can assist
Please see my code below
var changeConfirmCancelDialog;
function loadConfirmDialog() {
var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
changeConfirmCancelDialog = new dialogClass("change_confirm_cancel", false, 648, 250);
changeConfirmCancelDialog.setTitle(new GwtMessage().getMessage("Cancel Change Request"));
changeConfirmCancelDialog.render();
}
function moveToCancel(notes) {
var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
ga.addParam("sysparm_name", "getStateValue");
ga.addParam("sysparm_state_name", "canceled");
ga.getXMLAnswer(function(stateValue) {
g_form.setValue("state", stateValue);
g_form.setValue("work_notes", notes);
changeConfirmCancelDialog.destroy();
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_canceled");
});
}
current.work_end = gs.nowDateTime();
current.update();
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
I have also attached a screenshot of the code. Not this is also working well on the form but on the browser console. Also, note that my app was extended from the change request and I am only having this issue on the extended app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 12:16 PM
Hi @Malo
The syntax is incorrect in your code. below is the example how to use both client & server side script in UI actions
Also, make sure you filled in Action Name, Client, OnClick fields.
// Client-side onclick function
function resolveIncident() {
// Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
g_form.setValue('resolved_by', g_user.userID);
// Call the UI action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}
// Code that runs without 'onclick'
// Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();
// Server-side function
function serverResolve() {
current.incident_state = IncidentState.RESOLVED;
current.state = IncidentState.RESOLVED;
current.resolved_by = gs.getUserID();
current.update();
}
Please mark as accepted & helpful if it suffice your requirement 🙂