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

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!

Hey @Zach Koch - this looks like it should suit my needs. I'll modify my code and get back with results. 

Hey @Zach Koch

 

I ended up doing something different, using a GlideAjax call to handle the server-side scripting and moved everything into functions. The Onclick was required though so I appreciate seeing that error. Accepting as solution!

Great! I'm glad you were able to come up with a solution.

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!