- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:11 AM
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
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2024 08:25 AM - edited 07-02-2024 08:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2024 06:26 AM
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...