- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 07:15 AM
I want to create a UI action on a problem_task record in Service Operations Workspace to create the PDF of the current problem_task record.
I Created one UI Action and added the script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 05:21 AM
for workspace you need to use workspace client script
something like this will work
Ensure those 2 checkboxes are true to show that button in workspace
function onClick(g_form) {
var uri = '/' + g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue() + '&PDF';
open(uri);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2025 07:53 PM
Hello @rohit_hatkar1,
- Navigate to System UI > UI Actions.
- Click New.
- Name: Give your UI action a descriptive name (e.g., "Generate PDF").
- Table: Select the table your UI action will apply to (e.g., "Incident").
- Order: Set the order in which the UI action will appear (lower numbers appear first).
- Action name: Give it an internal name (e.g., "generate_pdf").
- Client: Check this box if you want the action to execute on the client-side (e.g., using JavaScript).
- Form link: Check this box to display the UI action as a button on the form.
- Show insert: Check this box if you want the button to appear when a new record is being inserted.
- Show update: Check this box if you want the button to appear when an existing record is being updated.
- Onclick: (If Client is checked) Enter the name of the client-side function to execute (e.g., "generatePDF()").
- Script: (If Client is unchecked) Enter the server-side script to execute.
- Using Client-side Script (if "Client" is checked):
- You'll typically use
g_form.getTableName()
andg_form.getUniqueValue()
to get the table name and sys_id of the current record. - Construct a URL that points to the record's PDF export endpoint (e.g.,
instance.service-now.com/<table_name>.do?sys_id=<sys_id>&PDF
). - Use
g_navigation.openPopup()
to open the PDF in a new window or tab.
- You'll typically use
function generatePDF() {
var sysparm_table = g_form.getTableName();
var sysparm_sys_id = g_form.getUniqueValue().toString();
var instanceURL = window.location.origin; // Get the instance URL
var url = instanceURL + "/" + sysparm_table + ".do?PDF&sys_id=" + sysparm_sys_id;
g_navigation.openPopup(url);
}
If this is helpful, please hit the thumbs up button and accept the correct solution by referring to this solution in the future; it will be helpful to them.
Thanks & Regards,
Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 05:00 AM
Hello @abb,
Thanks for your reply. I tried some code with ui action as described by you and it's working in the default view of the record but in Service Operations Workspace view it's not working.
var uri = g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue() + '&PDF';
g_navigation.open(uri);
Thanks & Regards,
Rohit Hatkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 05:21 AM
for workspace you need to use workspace client script
something like this will work
Ensure those 2 checkboxes are true to show that button in workspace
function onClick(g_form) {
var uri = '/' + g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue() + '&PDF';
open(uri);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 07:44 AM
Hi @Ankur Bawiskar ,
Thanks for the solution. The issue was with the script.
Thanks & Regards,
Rohit Hatkar