How to create a UI action and UI page to print a record

hamidouche
Kilo Expert

Hi all,

I am pretty new to SN. Here is what I wanted to do:

I want to create a button "print" that will launch the printing of the record.

I have already created the UI action.

My question is the following:

Where do I add the "window.print()" command? is it inside the UI action script or inside the UI page.

A specific answer with an example would be greatly appreciated!

Please do not refer me to SN documentation on UI actions or Pages, I already covered that!

ps. I want to implement the solution as stated above, not with the export to pdf or other options.

Thanks for your help

 

1 ACCEPTED SOLUTION

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

you have to use the window.print() command in the UI Page, below an example:

<input name="btnGo" id="btnGo" type="button" value="Print" onclick="window.print()"></input>

Hope this will fit your need.

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thanks you

Cheers
Alberto

 

 

View solution in original post

7 REPLIES 7

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

you have to use the window.print() command in the UI Page, below an example:

<input name="btnGo" id="btnGo" type="button" value="Print" onclick="window.print()"></input>

Hope this will fit your need.

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thanks you

Cheers
Alberto

 

 

Hi Alberto,

Thank you for your answer. It works indeed, although there's a catch: When I click on the print icon, the print preview shows the dialog window (to print the record). This user had the same issue:

https://community.servicenow.com/community?id=community_question&sys_id=74050f2ddbd8dbc01dcaf3231f9619e3

Do you know of a better way to remove the dialog window?

I added a window..close() right after "window.open()" as suggested in the thread. It's not working.

Thanks again

 

Try with this function:

GlideDialogWindow.get().destroy(); 

I already tried it in the client script section: the result is that the dialog window pops up and disappears immediately.

Should I call it inside another function maybe?