For partners that build or integrate commercially available applications and service solutions with the Oracle Cloud Platform
For partners that provide implementation or managed services around Oracle Cloud Applications
Hi folks,
I am trying to generated PDF using CPM. I know we can go with Addins which is little easier compared to CPMs, but I cant due to various other reasons.
I am trying with these two libraries:
tcpdf has the format I want, which takes in html as a parameter and converts to PDF.
But the problem is, no file operations are allowed in CPM no file_get_contentst(), file_read, file_write() etc.
So,
TIA,
Pramod V
HTML is stored in a message base. I have added place holders to replace the values from actual record.
~VIP
Please check SimpleHtmlDom.php Library in CP Core Framework folder.
This Library has functions to load HTML from File Source or Direct String.
The problem is not loading html or reading from message base, it is performing file operations. Those things are disabled in CPM.
~VIP
Im sure these file operations work in Custom Scripts.
Call the Custom Script from CPM using cURL.
Here's a sample for downloading file through Custom Script.
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
These are the only file operations I have used in Custom Scripts so far.
Thanks for this,
How do we use this in CPM? Sorry if I am pushy!
~VIP
No prob.
And, not sure about file methods in CPM.
CPM testing is difficult and time consuming.
So most of my CPMs work by calling Custom Scripts.
Do you mean you embed CPM logic inside custom script and check them?
~VIP
Yeah basically I move all CPM code in a Custom Script.
Pass the $obj->ID in URL parameter.
And call the Custom Script from CPM.
It does the same thing exactly. Just that your CPM has to be Async.
But how do you "call" Custom script from CPM?
Like $url = <custom_script_url>/obj/<obj_ID>
and then you do a cURL?
~VIP
$i_id = $incident->ID; // This example is Incident CPM
$siteInterfaceRoql = RNCPHP\ROQL::query("Select * from SiteInterface")->next()->next();
$interfaceName = str_replace("_", "-", $siteInterfaceRoql["DisplayName"]);
$siteName = $siteInterfaceRoql["Name"];
$url = "https://" . $interfaceName . ".custhelp.com/cgi-bin/" . $siteName . ".cfg/php/custom/cpm_incident_create.php?i_id=$i_id";
// With this ROQL I generate the URL because when you create a Test site or Upgrade site, then the --tst or --upgrade will come automatically in the URL.
load_curl();
dl('curl_php5.so');
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($handle);
$curl_error = curl_error($handle);
curl_close($handle);
That's it. This comes in the apply() function.
dl('curl_php5.so');
what is this file? Is it equivalent to curl_init()?
~VIP
dl('curl_php5.so') is a library required to load cURL in CPMs.
No its not related to curl_init().
Ooh that complicates it.
Here's what I would do:
1. One Sync CPM to check $obj and $obj->prev. At the end of this CPM, set a field value to something.
2. One Async CPM which has the cURL call to Custom Script.
This CPM will be triggered through business rules.
When Field (Field modified in step 1) Modified this Edit, then Execute CPM
If this is Incident CPM, then you can even add another condition: If Incident Updated from Public API -> Customised Process.