UI Action no longer working with modified script

MBarrott
Mega Sage

I modified the Planning UI Action so that it will check to see if a specific task has been closed. If the record is still active then it will display an alert/error, otherwise it will just update the record. 

 

I'm aware that the final if is still using current and it's on the client side but right now the button does nothing. 

 

Weirdly, if I add an alert before the first var declaration it will display after updating the UI Action. 

 

// get sys_id for current project record
var prjRec = g_form.getValue('number');

// declare gliderecord and query against related project and stage gate requirements
var prjGlid = new GlideRecord('pm_project_task');
prjGlid.initialize();
prjGlid.addQuery('top_task.number', prjRec);
prjGlid.addEncodedQuery('short_description=Planning Phase Completion^key_milestone=true');
prjGlid.query();

var row = prjGlid.getRowCount();
var checkCount = 0;

while(prjGlid.next() && row == 1)
{
	alert('in loop');
	
	if(prjGlid.active == true)
	{
		alert('Invalid Update - Planning Stage Gate is not complete');
		checkCount++;
	}
}

if(checkCount == 0)
{
	alert('in final if');
	current.phase = 'planning'; // ori
	current.state = '2'; // ori
	current.update(); // ori
	action.setRedirectURL(current); // ori
}

 

 

 

1 ACCEPTED SOLUTION

Zach Koch
Giga Sage
Giga Sage

Since you have the Client box checked on the record for this UI action, you need to add your Function that is declared from your Script into the Onclick field to get it to do anything when clicked. You'll also need to do a lot of changes to your code to run Client and Server Side script in the same code.

Here are some examples from the docs page on how you can do that

Docs page for UI action 

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

5 REPLIES 5

Hey @Zach Koch

Think I spoke too soon, I switched the UI Action back to server side and while it appears to be much simpler logic wise I'm getting a weird unexpected result. Let me know if you've ever experienced this before: https://www.servicenow.com/community/developer-forum/ui-action-redirects-to-previous-page/m-p/297993...