Uncaught RefereneError exception UI action

Shawna2
Giga Contributor

I am having issues with a line of code and assistance is highly appreciated

 

I modified cancel change UI and I added line of code

current.work_end = gs.nowDateTime();
current.update();

 

This code is just to update the actual end date with current date/time. Code works like a charm but cause the above error when setting up ATF and also in the browser console

 

Followed recommendation from

UI Action error: Unchanged ReferenceError: current... - Page 2 - ServiceNow Community

 

Hoewever, this does not work. The date is not populating

 

Doing a background script to check the code, I get the below error

 

evaluator: com.glide.script.RhinoEcmaError: Cannot set property "work_end" of null to "2023-10-04 09:01:43" script : Line(1) column(0) ==> 1: current.work_end = gs.nowDateTime(); 2: current.update();

 

I cannot seem to figure this one out. Please help!!!!

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Shawna,

There are a number of replies on the post you referenced, but none of them marked as correct yet, so which one(s) did you try?  Where did you add the line(s) of code?  My OOB Cancel Change UI Action already contains a current.update(); line, so you shouldn't need to add another one.  Does it work if you add the current.work_end line inside the setRedirect() function before the existing current.update()?  If not, you'll need a line first to call the Action name like this:

var changeConfirmCancelDialog;

function setChangeCancelState() {
	g_form.setValue("state", "4");
    
    //Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'state_model_move_to_canceled'); //MUST call the 'Action name' set in this UI Action
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.work_end = gs.nowDateTime();
    current.update();
    action.setRedirectURL(current);
}

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Hi Shawna,

There are a number of replies on the post you referenced, but none of them marked as correct yet, so which one(s) did you try?  Where did you add the line(s) of code?  My OOB Cancel Change UI Action already contains a current.update(); line, so you shouldn't need to add another one.  Does it work if you add the current.work_end line inside the setRedirect() function before the existing current.update()?  If not, you'll need a line first to call the Action name like this:

var changeConfirmCancelDialog;

function setChangeCancelState() {
	g_form.setValue("state", "4");
    
    //Call the UI Action and skip the 'onclick' function
    gsftSubmit(null, g_form.getFormElement(), 'state_model_move_to_canceled'); //MUST call the 'Action name' set in this UI Action
}

if (typeof window == 'undefined')
   setRedirect();

function setRedirect() {
    current.work_end = gs.nowDateTime();
    current.update();
    action.setRedirectURL(current);
}

 

Work Brad, I am still scratching my head how I missed that existing current. update();

I appreciate your help on this one.

 

Best Regards

Cool.  Happy to help!

 

 

Connect with me https://www.linkedin.com/in/brad-bowman-321b1567/