How to Create UI action on SOW to create the PDF of Current Record.

rohit_hatkar1
Tera Contributor

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 

 

var uri = '/' + g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue() + '&PDF';
    window.location = uri;
 
this is working fine in the default view  but when I am trying to do the same thing for Service Operations Workspace view it's not working.
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@rohit_hatkar1 

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);

}

AnkurBawiskar_0-1750335657497.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Abbas_5
Tera Sage
Tera Sage

Hello @rohit_hatkar1,

 

To create a UI action in ServiceNow that generates a PDF of the current record, you'll need to create a UI action, define the logic for generating the PDF, and potentially include a link or button on the form for users to trigger the action. 
Here's a step-by-step guide:
1. Create the UI Action:
 
  • 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. 
     
2. Implement the PDF Generation Logic:
  • Using Client-side Script (if "Client" is checked):
    • You'll typically use g_form.getTableName() and g_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. 
       
        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

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

Ankur Bawiskar
Tera Patron
Tera Patron

@rohit_hatkar1 

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);

}

AnkurBawiskar_0-1750335657497.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

Thanks for the solution. The issue was with the script.

 

Thanks & Regards,

Rohit Hatkar