Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Configurable Workspace: Refresh Page or Attachments Sidebar on UI Action completion

Michal Sadowski
Mega Sage

Hi Workspace Superstars,

I've created a UI Action that is based on PDFGenerationAPI and generates the PDF document based on the current Purchase Order records and related data.

MichalSadowski_0-1739984756654.png

Unfortunately after the process is completed, the attachment is not immediately visible in the Attachments section of the sidebar and I am not able to force the form refresh of the entire workplace form either. This creates a poor UX where the user must manually refresh the page to see the outcome of their UI Action.

 

My UI Action is set to client = false and here's the script:

 

 

 

 

 

 

 

// Build the PDF content and attach it to the record

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

var gr = new GlideRecord("proc_po");
var currentRecord = gr.get(current.sys_id);
var html;

var currentDate = new GlideDate();
var formattedDate = currentDate.getByFormat("dd.MM.yyyy");

// html string including server side scripting to dynamically build the document goes here
if (currentRecord) {
    html = ;
}

var hfInfo = new Object();
// lots of hfInfo properties are here

var result = v.convertToPDFWithHeaderFooter(html, "proc_po", current.sys_id, "ITBestellung-" + current.number + "-" + formattedDate, hfInfo);
action.setRedirectURL(current);

 

 

 

 

 

 

 

I did experiment with setting UI Action to client = true and adding the following code in Workspace Client Script but then it breaks the main functionality of PDF generation both in classic UI and in Workspace:

 

 

 

function onClick(g_form) {
	g_form.reload();
}

 

 

 

 Can I have the best of both worlds - UI Action to generate PDF and to refresh the page in classic UI and Workspace to immediately reveal the attachment. Even better if in Workspace there's a way not to refresh the whole page, just the Attachment section of the sidebar or something similar.
Any help appreciated.
 

 

1 REPLY 1

Thobie Sakamaki
Tera Contributor

Hi Michal! Any luck on accomplishing this? I'm facing the same issue but with the Customer Order [sn_ind_tmt_orm_order] table. I actually have the same functionality applied to Quote table [sn_quote_mgmt_core_quote] and it is working well. The attachment is added after 2 seconds even without setRedirect or .reload. 😕