Ui action script doesn´t work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I'm creating a UI action (button) in the ServiceNow sc_task table called "Create Story". The button should trigger a process to create a story record in the rm_story table and copy fields and attachments from the related Requested Item (RITM) to the new story. However, the button isn't working as expected because the script isn't even being called. I need guidance on how to implement the script so that clicking the button starts the flow or executes the necessary actions. We've already tried all approaches and configurations, and since the script isn't running, even looking at the log table is pointless.
The script runs on background scripts interface, so the script is ok. But why on earth he doesn´t run in the UI action is a mystery!
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Big Alex
Use this simplified code (remove the function wrapper):
if (current && current.assigned_to != '570743494740765045a1fb72036d431f') {
current.assigned_to = '570743494740765045a1fb72036d431f';
current.update();
action.setRedirectURL(current);
gs.addInfoMessage('Atribuído ao usuário padrão com sucesso.');
} else {
gs.addInfoMessage('Registro já atribuído ou inválido.');
}
Happy to help! If this resolved your issue, kindly mark it as the correct answer ✅ and Helpful and close the thread 🔒 so others can benefit too.
Warm Regards,
Deepak Sharma
Community Rising Star 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Step 1: Verify UI Action Configuration
Navigate to System UI > UI Actions and open your "Create Story" UI Action. Confirm these settings:
- Table: sc_task
- Action name: create_story (no spaces, lowercase)
- Active: Checked
- Form button: Checked
- Show insert: Unchecked
- Show update: Checked
- Client: Unchecked (this is critical - must be false for server-side execution)
- Onclick: Leave blank (do NOT put code here if Client is unchecked)
- Condition: Leave blank initially for testing
- Script field: This is where your server-side code goes
Step 2: Correct Script Implementation
Since your background script works, place it in the Script field (NOT the Onclick field):
(function() {
// Get the current sc_task record
var task = current;
// Get the related RITM
var ritm = task.request_item.getRefRecord();
if (!ritm || !ritm.isValidRecord()) {
gs.addErrorMessage('No valid Requested Item found for this task');
return;
}
// Create the story record
var story = new GlideRecord('rm_story');
story.initialize();
// Copy fields from RITM to Story
story.short_description = ritm.short_description;
story.description = ritm.description;
// Add other field mappings as needed
var storyID = story.insert();
if (storyID) {
// Copy attachments from RITM to Story
var sa = new GlideSysAttachment();
sa.copy('sc_req_item', ritm.sys_id, 'rm_story', storyID);
gs.addInfoMessage('Story ' + story.number + ' created successfully');
// Optional: Redirect to the new story
action.setRedirectURL(story);
} else {
gs.addErrorMessage('Failed to create story');
}
})();
Step 3: Critical Settings for Server-Side Execution
The Client checkbox determines execution context:
- Client = false (unchecked): Script runs on SERVER → Use the Script field → Can access GlideRecord, current, action
- Client = true (checked): Script runs in BROWSER → Use the Onclick field → Cannot access server objects directly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello @Big Alex ,
You can check the below points one more time for debugging
1.Ensure the client check box not checked
2.Check the Condition field if your condition returns false, the UI Action loads but the script will never run.
3.Check Form button and Show insert, Show update ensure the button is visible under the correct conditions.