Need help with using Document template script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 11:18 PM
Hi all ,
We have a document block created and a document block content created for a particular table with some filter conditions. In the HTML body we want to call a document template script.I have not used it before and hence have some doubts.
We want to do some calculations based on the fields of the table used in the Document Block. That should apply for all the records filtered in the condition field of the Document Block content .Can current be used in the document template script in a Glide Record Query of the table?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-09-2024 11:21 PM
Hi,
Try below approach:
<!DOCTYPE html>
<html>
<head>
<title>Document Template</title>
</head>
<body>
<h1>Document Template</h1>
<!-- Your HTML content here -->
<script>
// Assuming your document template is associated with a particular table, let's say 'incident'
var gr = new GlideRecord('incident');
// Apply a filter based on conditions from the Document Block Content
gr.addQuery('your_condition_field', 'your_condition_value');
gr.addQuery('additional_condition_field', 'additional_condition_value');
// Add more conditions as needed
gr.query();
while (gr.next()) {
// Access fields and perform calculations
var fieldValue = gr.getValue('your_field_name');
// Perform your calculations here based on the field values
// Output the calculated values or use them as needed in your template
document.write('<p>Calculated value for ' + gr.getValue('number') + ': ' + calculatedValue + '</p>');
}
</script>
</body>
</html>
Regards,
Shoheb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:01 AM
Hi Shoheb,
Thanks for your reply. So, do you mean to say that all the filter conditions pertaining to the table selected given in the document block content record have to be given in the document template script also? I wanted to know whether like in an email script where we current refers to the current record of the notification, we have anything here which will refer to the records filtered in the block content.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2024 01:08 AM
If you want to achieve this via email script, try below code:
// Assuming your document template is associated with a particular table, let's say 'incident'
var gr = new GlideRecord('incident');
// Apply a filter based on conditions from the Document Block Content
gr.addQuery('your_condition_field', 'your_condition_value');
gr.addQuery('additional_condition_field', 'additional_condition_value');
// Add more conditions as needed
gr.query();
var emailBody = '<!DOCTYPE html>' +
'<html>' +
'<head>' +
'<title>Document Template</title>' +
'</head>' +
'<body>' +
'<h1>Document Template</h1>';
while (gr.next()) {
// Access fields and perform calculations
var fieldValue = gr.getValue('your_field_name');
// Perform your calculations here based on the field values
var calculatedValue = fieldValue * 2; // Replace with your actual calculation logic
// Output the calculated values or use them as needed in your template
emailBody += '<p>Calculated value for ' + gr.getValue('number') + ': ' + calculatedValue + '</p>';
}
emailBody += '</body>' +
'</html>';
// Use 'email' object to send the email with the generated HTML content
email.addMessage(emailBody);
email.send();
Regards,
Shoheb