- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:14 AM
Hello.
I created a Business Rule that export the form to pdf automatically and attach it to the form.
However my Pricing Speciation Related List doesn't appear in the PDF.
What is the problem?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:21 AM
Please try below code -
(function executeRule(current, previous /*null when async*/) {
// check if related lists have loaded
if (current.getValue('loaded_related_lists') == 'true') {
// Generate PDF and attach
generateAndAttachPDF(current);
} else {
// a delay and then set 'loaded_related_lists' to 'true'
gs.sleep(5000); // Adjust the sleep time as needed
current.loaded_related_lists = 'true';
current.update();
// generate PDF and attach
generateAndAttachPDF(current);
}
})(current, previous);
function generateAndAttachPDF(current) {
var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName() + '.do?PDF&sys_id=' + current.sys_id;
rm.setEndpoint(url);
rm.setBasicAuth('idanby@bynet.co.il', '1234');
// Execute the REST message
var response = rm.execute();
// Check if the response was successful before attaching
if (response.getStatusCode() == 200) {
var attachment = new GlideSysAttachment();
attachment.addAttachment(current, current.getTableName(), current.sys_id, current.number + '.pdf', 'application/pdf', response.getBody());
} else {
gs.error('PDF generation failed. Status Code: ' + response.getStatusCode());
}
}
I think you can also try using a Scheduled Job to run the PDF generation and attachment creation asynchronously, giving the system more time to prepare the data.
Thanks,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 04:21 AM
Please try below code -
(function executeRule(current, previous /*null when async*/) {
// check if related lists have loaded
if (current.getValue('loaded_related_lists') == 'true') {
// Generate PDF and attach
generateAndAttachPDF(current);
} else {
// a delay and then set 'loaded_related_lists' to 'true'
gs.sleep(5000); // Adjust the sleep time as needed
current.loaded_related_lists = 'true';
current.update();
// generate PDF and attach
generateAndAttachPDF(current);
}
})(current, previous);
function generateAndAttachPDF(current) {
var rm = new sn_ws.RESTMessageV2();
rm.setHttpMethod('GET');
var url = gs.getProperty("glide.servlet.uri") + current.getTableName() + '.do?PDF&sys_id=' + current.sys_id;
rm.setEndpoint(url);
rm.setBasicAuth('idanby@bynet.co.il', '1234');
// Execute the REST message
var response = rm.execute();
// Check if the response was successful before attaching
if (response.getStatusCode() == 200) {
var attachment = new GlideSysAttachment();
attachment.addAttachment(current, current.getTableName(), current.sys_id, current.number + '.pdf', 'application/pdf', response.getBody());
} else {
gs.error('PDF generation failed. Status Code: ' + response.getStatusCode());
}
}
I think you can also try using a Scheduled Job to run the PDF generation and attachment creation asynchronously, giving the system more time to prepare the data.
Thanks,
Tushar