Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
User avatar
By satyaprakashsp
#807391
Dear All,

Can anyone help please,

I have the following trigger code
Code: Select all
if(is_array(@=supplierList)){
	foreach(@=supplierList as $row){
		@@SupplierID = $row["SUPPLIERID"];

		if(isset($row["ADDRESS"]) && $row["ADDRESS"]!="")
			@@ADDRESS_OR_NAME = $row["ADDRESS"];
		else
			@@ADDRESS_OR_NAME = $row["SUPPLIERNAME"];
		
		@@extSupplierName = $row["SUPPLIERNAME"];
		@@todayDate = getCurrentDate();
		
		@@gridInvoiceDetail = executeQuery("SELECT ROWID, CASENUMBER, AMONTORAVAL, PRODUCTFAMILY,
		SUPPLIERID, SUPPLIERNAME, PROCUREMENTCODE, DIVISIONID, DIVISIONNAME, 
		PLATEFORME AS DAPLATEFORME,
		EAN, DESIGNATIONARTICLE, VA, PROMORPERM AS DPROMORPERM, CODERUPTURECOMMANDE,
		CODERUPTURELIVRAISON, DATELIVR, NOCDE, RELIQUAT, QTECDEE, QTELIVREE, ECARTCDELIVRE,
		MONTANTCDEHT, MONTANTLIVREHT, MONTANTRUPTUREHT, MONTANTPENALITEHT, AEXCLURECAUSECORA,
		MONTANTAFACTURERPOTENTIEL, MONTANTAFACTURERBRUTINCLUANTLESRUPTURESENCODES0ET8,
		ECARTBRUTENETTE FROM pmt_invoicesdetaildata Where
		SUPPLIERID='".$row["SUPPLIERID"] ."' AND CASENUMBER=".@@APP_NUMBER);
		
		@@docID = "9623107915a094870dc75e4077532863"; 
		@@varToSend = array('ADDRESS_OR_NAME' => @@ADDRESS_OR_NAME,
						   'SUPPLIERID' => @@SupplierID,
						   'todayDate' => @@todayDate,
						   'gridInvoiceMaster1' => $row,
						   'gridInvoiceDetail1' => @=gridInvoiceDetail);
		@@sendRetVal = PMFSendVariables(@@APPLICATION,@@varToSend);
		PMFGenerateOutputDocument(@@docId,@@APPLICATION);
	}
}
I have tried to generate this output document in all possible ways, but its always giving an error This row doesn't exist!

I have tried to do it for one single row of the main foreach loop by applying break;
Have also tried removing the loop altogether and run this code for only one row, but it is always giving this error.
The output document works fine otherwise.

Can someone please help what's wrong with the code.
I saw a post in Processmaker 2.x group that PMFGenerateOutputDocument() had a bug, is that fixed in version 3.x or I am hitting the same bug, If yes what could be the workaround for this.

Please help soon.

Best regards,
Satya
User avatar
By amosbatto
#812364
The problem is that you define the variable as @@docID, but then use it as @@docId. Variables are case sensitive.

Try it this way:
Code: Select all
      @@docID = "9623107915a094870dc75e4077532863";
      @@varToSend = array('ADDRESS_OR_NAME' => @@ADDRESS_OR_NAME,
                     'SUPPLIERID' => @@SupplierID,
                     'todayDate' => @@todayDate,
                     'gridInvoiceMaster1' => $row,
                     'gridInvoiceDetail1' => @=gridInvoiceDetail);
      @@sendRetVal = PMFSendVariables(@@APPLICATION,@@varToSend);
      PMFGenerateOutputDocument(@@docID);
#812386
Hello,

One more trouble :cry:
Code: Select all
if (is_array(@=supplierList)) {
    foreach (@=supplierList as $row) {
        @@SupplierID = $row["SUPPLIERID"];

        if (isset($row["ADDRESS"]) && $row["ADDRESS"] != "")
            @@ADDRESS_OR_NAME = $row["ADDRESS"];
        else
            @@ADDRESS_OR_NAME = $row["SUPPLIERNAME"];
        
        @@extSupplierName = $row["SUPPLIERNAME"];
        @@todayDate = getCurrentDate();
        
        @@gridInvoiceDetail = executeQuery("SELECT ROWID, CASENUMBER, AMONTORAVAL, PRODUCTFAMILY,
        SUPPLIERID, SUPPLIERNAME, PROCUREMENTCODE, DIVISIONID, DIVISIONNAME, 
        PLATEFORME AS DAPLATEFORME, EAN, DESIGNATIONARTICLE, VA, 
        PROMORPERM AS DPROMORPERM, CODERUPTURECOMMANDE,
        CODERUPTURELIVRAISON, DATELIVR, NOCDE, RELIQUAT, QTECDEE, QTELIVREE, ECARTCDELIVRE,
        MONTANTCDEHT, MONTANTLIVREHT, MONTANTRUPTUREHT, MONTANTPENALITEHT,
        AEXCLURECAUSECORA, MONTANTAFACTURERPOTENTIEL, 
        MONTANTAFACTURERBRUTINCLUANTLESRUPTURESENCODES0ET8, ECARTBRUTENETTE 
        FROM pmt_invoicesdetaildata 
        Where SUPPLIERID='".$row["SUPPLIERID"]."' AND CASENUMBER=".@@APP_NUMBER);
        
        @@docID = "9623107915a094870dc75e4077532863"; 
        @@varToSend = array('ADDRESS_OR_NAME' => @@ADDRESS_OR_NAME,
                           'SUPPLIERID' => @@SupplierID,
                           'todayDate' => @@todayDate,
                           'extSupplierName' => @@extSupplierName,
                           'gridInvoiceMaster1' => array($row),
                           'gridInvoiceDetail1' => @=gridInvoiceDetail);
        @@sendRetVal = PMFSendVariables(@@APPLICATION, @@varToSend);
        PMFGenerateOutputDocument(@@docID);
    }
}
 
@@extSupplierName variable I am using it in name of Output document, Output Filename generated as @=Year-@=Month-@=extSupplierName
extSupplierName is always coming blank and thus the code is generating multiple versions of the same document.

Would highly appreciate a quick help, Please.

Best regards.
User avatar
By amosbatto
#812389
You are converting arrays to stings. You need to reference arrays as @=variable, not as @@variable.

Use this code:
Code: Select all
        @=varToSend = array(
                           'ADDRESS_OR_NAME' => @@ADDRESS_OR_NAME,
                           'SUPPLIERID' => @@SupplierID,
                           'todayDate' => @@todayDate,
                           'extSupplierName' => @@extSupplierName,
                           'gridInvoiceMaster1' => array($row),
                           'gridInvoiceDetail1' => @=gridInvoiceDetail);
        @@sendRetVal = PMFSendVariables(@@APPLICATION, @=varToSend); 
#812391
Thanks amosbatto,

Corrected things the file names are correct now, but the code is still generating only one file, which is based on the last record in the gridInvoiceMaster1 variable and that too the generated file is corrupt.

Am I trying to do something that won't work in Processmaker all together?
Is there any way to run that trigger in the background in a different thread or from command shell?

Best regards
Satya
User avatar
By amosbatto
#812416
If you want to be able to see all the Output Document files, you need to select the option Enable Versioning in the properties of the Output Document.

Does the data from your database cause the corruption? What happens if you comment out PMFSendVariables() so it generates the Output Document without your database data?

You should generate the DOC file for the Output Document and then open it with a plain text file to see what data is getting inserted.
#812450
Instead of versioning, I wanted the code to generate different filename, I have made sure the file name is coming from the case variables and are distinct. But somehow that loop is only generating 1 file which is based on the record in the last iteration of the loop.
It looks like the last PMFSendVariables() call is overwriting previous ones.

Any ideas what could be an alternate solution to this problem.
I can generate these documents using command line tools but how do I attach the generated files to the case?
User avatar
By amosbatto
#812462
satyaprakashsp wrote:Instead of versioning, I wanted the code to generate different filename, I have made sure the file name is coming from the case variables and are distinct. But somehow that loop is only generating 1 file which is based on the record in the last iteration of the loop.
It looks like the last PMFSendVariables() call is overwriting previous ones.

Any ideas what could be an alternate solution to this problem.
I can generate these documents using command line tools but how do I attach the generated files to the case?
Create an Input Document in your process. Copy the UID from the Input Document to use in your code. Then, use code like this:
Code: Select all
$inputDocId = '1234567890abcde1234567890abcde'; //set to the ID of the Input Document
$outputDocId = "9623107915a094870dc75e4077532863"; //set to the ID of the Output Document
$caseId = @@APPLICATION;

if (is_array(@=supplierList)) {
    foreach (@=supplierList as $row) {
        @@SupplierID = $row["SUPPLIERID"];

        if (isset($row["ADDRESS"]) && $row["ADDRESS"] != "")
            @@ADDRESS_OR_NAME = $row["ADDRESS"];
        else
            @@ADDRESS_OR_NAME = $row["SUPPLIERNAME"];
        
        @@extSupplierName = $row["SUPPLIERNAME"];
        @@todayDate = getCurrentDate();
        
        @@gridInvoiceDetail = executeQuery("SELECT ROWID, CASENUMBER, AMONTORAVAL, PRODUCTFAMILY,
        SUPPLIERID, SUPPLIERNAME, PROCUREMENTCODE, DIVISIONID, DIVISIONNAME, 
        PLATEFORME AS DAPLATEFORME, EAN, DESIGNATIONARTICLE, VA, 
        PROMORPERM AS DPROMORPERM, CODERUPTURECOMMANDE,
        CODERUPTURELIVRAISON, DATELIVR, NOCDE, RELIQUAT, QTECDEE, QTELIVREE, ECARTCDELIVRE,
        MONTANTCDEHT, MONTANTLIVREHT, MONTANTRUPTUREHT, MONTANTPENALITEHT,
        AEXCLURECAUSECORA, MONTANTAFACTURERPOTENTIEL, 
        MONTANTAFACTURERBRUTINCLUANTLESRUPTURESENCODES0ET8, ECARTBRUTENETTE 
        FROM pmt_invoicesdetaildata 
        Where SUPPLIERID='{$row['SUPPLIERID']}' AND CASENUMBER=".@@APP_NUMBER);
         
        @=varToSend = array('ADDRESS_OR_NAME' => @@ADDRESS_OR_NAME,
                           'SUPPLIERID' => @@SupplierID,
                           'todayDate' => @@todayDate,
                           'extSupplierName' => @@extSupplierName,
                           'gridInvoiceMaster1' => array($row),
                           'gridInvoiceDetail1' => @=gridInvoiceDetail);
        @@sendRetVal = PMFSendVariables($caseId, @=varToSend);
        PMFGenerateOutputDocument($outputDocId);
        
        //lookup generated output document file in the database:
        $sql = "SELECT * FROM APP_DOCUMENT WHERE APP_UID='$caseId' AND DOC_ID='$outputDocId' 
             ORDER BY DOC_VERSION DESC";
        $aDocs = executeQuery($sql);
        if (empty($aDocs)) {
            throw new Exception("No generated Output Document file for ID '$outputDocId' in APP_DOCUMENT table.");
        }
        
        $fileId = $aDocs[1]['APP_DOC_UID'];
        $fileVersion = $aDocs[1]['DOC_VERSION'];
        $g = new G();
        $newFilePath = PATH_DOCUMENT . $g->getPathFromUID($caseId) . PATH_SEP . "outdocs" . PATH_SEP . 
            "{$fileId}_{$fileVersion}.pdf";
        $inputDocFileId = PMFAddInputDocument($inputDocId, null, 1, 'INPUT', '', null,
            @@APPLICATION, @%INDEX, @@TASK, @@USER_LOGGED, 'file', $newFilePath);
        if ($inputDocFileId) {
           //set the filename of the Input Document file:
           $d = new AppDocument();
           $aFileInfo = $d->Load($inpDocFileId, 1);
           $aFileInfo['APP_DOC_FILENAME'] =  'invoice_' . @@ADDRESS_OR_NAME . '.pdf'; //new filename
           $d->update($aFileInfo);
        }
    }
} 
I haven't tried this code, so it might require some debugging, but this will get you started.
See:
http://wiki.processmaker.com/3.0/Output ... ment_Files
http://wiki.processmaker.com/3.2/Proces ... ment.28.29
http://wiki.processmaker.com/3.0/Intern ... date.28.29

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]