When catalog item is submitted, attach variables to RITM as a PDF

AngusWIlliams
Tera Contributor

Hi,

 

I am looking for a current way, on RITM creation, to generate a PDF containing the variables of the catalog item submitted, and then attach this to the RITM.  I've seen the PDFGenerationAPI, and am aware this is a good way to go about it, but I don't have too much experience with scripting in this way. Does anyone have any code snippets to accomplish this or something similar? I especially want to add the display values to the PDF and not the underlying values.

Many thanks,
Angus 🙂

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @AngusWIlliams,

 

Can I ask the requirement or need for the variables to be attached as a PDF document? 

It is common practice to simply configure the form layout and add a new form section and tab displaying the variables. These can be read only (Recommended).

This allows 'fullfillers' or service desk task managing the requests to see exactly what a user has entered? Would that not suffice and provide an easier solution for all without the need for attachments etc.

 

- Open the Requested Item form.

- Right-click at the top and select 'Configure > Form Layout'

- At the bottom of the form under the slush bucket (as pictured below) - Click on 'New...' to create a New form section and tab. Call it variables for example. - Hit Save.

- With that new form section highlighted, look for the field called 'Variable Editor', and double click it to move it from the left side to the right - again as show below.

- Hit Save - you now have your variables on the form for everyone to see.

- (I'll find a script for you so you can make them read-only)

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

 

Screenshot 2024-04-29 at 14.27.30.pngScreenshot 2024-04-29 at 14.28.21.pngScreenshot 2024-04-29 at 14.28.55.png

View solution in original post

6 REPLIES 6

Ramz
Mega Sage

Hi @AngusWIlliams ,

I suggest to create a UI action . So this UI action will be visible to users/condition you specify and only they can download the variables as PDF

Write this code in UI action:

 

function generatePDF(){
var sysparm_table = g_form.getTableName();
var sysparm_sys_id = g_form.getUniqueValue().toString();
var link='https://dev113064.service-now.com/'; // Replace with  sys_parm to get the instace name 
var url = link+sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id;
g_navigation.openPopup(url);
}

 

Follow this article: https://www.servicenow.com/community/itsm-articles/how-to-generate-pdf-from-ui-action/ta-p/2831049

To download only the variables make sure to create a new view and include only the variable editor in the new view and append the view name to the url link

sample url with new view in the link:

var url = instanceName+sysparm_table + '.do?PDF&sys_id=' + sysparm_sys_id + "&sysparm_view=PDF";

 

Please mark my answer helpful/correct if it resolved your query

svani
Tera Contributor

Hi @Ramz ,

 

I have tried this script to get the variables on form.But once clicked it is showing only fields on RITM but not the variable editors .how to get them as well on the PDF form.

 

Thanks in advance