UI Action error: Unchanged ReferenceError: current is not defined

Malo
Tera Contributor

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

Malo_0-1696356208663.png

Please see error 

Malo_1-1696356355242.png

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 

8 REPLIES 8

Jace Benson
Mega Sage

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!

Anand Kumar P
Giga Patron
Giga Patron

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

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

sohi
Tera Contributor

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 🙂