Download catalog form variables as a word document and send it to user once the request is submitted

vivek chelpuri2
Tera Contributor

Hello all,

 

    Can you please let us know if there is any possibility of downloading the catalog form variables as a word document in servicenow. We need to download the form once the user fills it and submit it and we need to send it in a mail.

 

Thanks,

vivek

1 REPLY 1

Riya Verma
Kilo Sage
Kilo Sage

Hi @vivek chelpuri2 ,

Hope you are doing great.

 

To achieve the requirement of downloading the catalog form variables as a Word document in ServiceNow and sending it to the user via email, we can implement a solution that involves customizing the form submission process and utilizing the Document Generation functionality.

 

  1. Customize the form submission process by adding a business rule or a client script to trigger the document generation and email sending.

  2. Configure the Document Generation functionality in ServiceNow to generate a Word document based on the form variables entered by the user. This can be done using Microsoft Word templates or other supported document formats.

  3. Write a server-side script, such as a Script Include or a server-side business rule, to generate the Word document with the catalog form variables. You can utilize the GlideRecord API to fetch the form variable values and populate them in the document template.

  4. Use the Email Notification functionality in ServiceNow to send the generated Word document as an attachment to the user. This can be achieved by creating an email notification template and utilizing the GlideSysEmail API to send the email with the document attachment.

  5. Trigger the document generation and email sending process upon form submission. You can achieve this by adding the necessary code to the business rule or client script associated with the catalog item's submission.

Reference code snippet to demonstrate the generation of the Word document and sending it via email:

 

// Fetch the form variable values
var catalogItem = new GlideRecord('sc_cat_item');
if (catalogItem.get('sys_id', current.cat_item)) {
  var formVariables = new GlideRecord('sc_item_option_mtom');
  formVariables.addQuery('request_item', current.sys_id);
  formVariables.query();

  // Generate the Word document using the form variable values
  var document = generateWordDocument(formVariables);

  // Send the email with the document attachment
  var email = new GlideEmailOutbound();
  email.setSubject('Form Submission Document');
  email.setBody('Please find the attached document.');
  email.addAttachment(document); // Attach the Word document
  email.send(current.opened_by.email); // Send the email to the user's email address
}

// Function to generate the Word document
function generateWordDocument(formVariables) {
  // Code logic to populate the Word document template with form variable values
  // Return the generated Word document
}

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma