Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Set incident Resolved to current date and time

RudhraKAM
Tera Guru

Hello I have a UI Action on Incident for resolved state , up on clicking it should get the current time and populate in that resolved field 

Below is the code i am using 

what am i missing ? every thing is working except resolves at 

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);
g_form.setValue('resolved_at',gs.nowDateTime());

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();

function serverResolve(){
current.incident_state = IncidentState.RESOLVED;
//current.resolved_at =gs.nowDateTime();
current.update();
current.resolved_by = gs.getUserID();
}

1 ACCEPTED SOLUTION

If you are not able to do it, then here is the OOB code. You can replace it

 

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);
	
	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();

function serverResolve(){
	current.incident_state = IncidentState.RESOLVED;
	current.state = IncidentState.RESOLVED;
	current.update();
	current.resolved_by = gs.getUserID();
}

View solution in original post

16 REPLIES 16

rahulpandey
Kilo Sage

Hi, Comment below g_form.setValue('resolved_at',gs.nowDateTime()); And uncomment below current.resolved_at =gs.nowDateTime(); It should work then

 

Edit 

current.resolved_by = gs.getUserID();

Above would go above current.update();

 

i tried that but its not working 

find_real_file.png

Alikutty A
Tera Sage

Hello,

You should uncheck the client checkbox, remove the onclick function and just make a direct server call for this

Add these lines only. The client side logic is not required for this.

current.incident_state = 6;
current.resolved_at =gs.nowDateTime();
current.resolved_by = gs.getUserID();
current.update();


Thanks!