Friday, April 26, 2024

Pega send email notificaiton

 





2.1

String strFileName = tools.getParamValue("OutputFilePath");

PRFile objFile = new PRFile(strFileName); //some error checking

if(objFile.exists())

  objFile.delete();


2.2

call pxGenerateExcelFile

Params - Param.FileName, WEBWB!APPRSVS!XLSX

2.3

String strFileName = tools.getParamValue("OutputFilePath");

PRFile objFile = new PRFile(strFileName); //some error checking

if (!objFile.exists())

{

         attach = false;

} if(!objFile.isFile())

{

         attach = false;

}

tools.putParamValue("OutputLocation",objFile.getName()); if (!objFile.canRead())

{

         attach = false;

    throw new PRRuntimeException("Can't continue with file upload. File \"" + strFileName + "\" is unreadable.");

} //read the file into a buffer.

java.io.DataInputStream dis = null;

byte buffer [] = null;

try

{

    // dis = new java.io.DataInputStream(new java.io.FileInputStream(objFile));    

    dis = new java.io.DataInputStream(new PRInputStream(objFile));

    buffer= new byte[dis.available()];                

    dis.readFully(buffer);

    dis.close();

}

catch (Exception e)

{

    attach = false;

         throw new PRRuntimeException("Can't continue with file upload. Can't read File \"" + strFileName + "\"");            

} //encode the file to Base64 so that we can store it on the database

strFileData = Base64Util.encodeToString(buffer);

if (strFileData == null)

{

         attach = false;

         throw new PRRuntimeException("Can't continue with file upload. Couldn't encode the file to Base64 so that we can store it on the database");            

}

2.5

Page-new att (Embed-EmailAttachment)

2.6

Property-set att

.pyDecode=true

.pyData=local.strFileData

.pyName=Param.FileName


2.7 atts (Data-EmailAttachments)

Page-copy 

from: att

to: atts.pyAttachments(<APPEND>)


Param.AttachmentPage=atts

Thursday, April 18, 2024

Binary in the REST response

 https://docs-previous.pega.com/data-management-and-integration/87/configuring-rest-connector-receive-binary-attachments


Configuring a REST connector to receive binary attachments

Updated on April 6, 2022

Pega Platform can receive attachments regardless of the content type or response type. Configure a REST connector to receive attachments when your application connects to a service that responds with a binary stream, for example, a PDF file or XLS file.

Before you begin:
  1. Configure your REST connector to map the response to the clipboard.
    1. On the Methods tab of your REST connector, in the GET section, click the Response tab.
    2. In the Message data section, in the Map to field, select Clipboard.
    3. In the Map to key field, enter the map to key property and then click the rule opener.
      For example: .binaryxls
      Result: The Property Record Configuration page is displayed.
  2. Configure the java object property type and the map to key.
    1. On the Property Record Configuration page, enter a name for the property, choose a class that you want to associate with the property, and select a ruleset and a ruleset version in which you want to store the property.
      For more information, see Properties.
    2. Click Create and open.
    3. On the General tab, in the Property type section, click ChangeJava Object.
    4. Click Save.
    5. Click Save on the Connect REST rule form.
  3. In the activity, define the page on which the response is mapped.
    1. On the Steps tab of the activity, in the Method field, press the Down arrow key and select Page-New.
      For more information, see Page-New method.
    2. In the Step page field, press the Down arrow key and select the name of the page to be created by this method.
      For example: BinaryAttachment
    3. On the Pages & Classes tab, enter the name of the page that you reference in step 3b and the class to which the page belongs.
  4. Call the service from the activity by using the Connect-REST method.
    1. On the Steps tab of the activity, click Add a step.
    2. In the Method field, press the Down arrow key and select Connect-REST.
    3. In the Method Parameters section, in the ServiceName field, enter the name of the service that you use to retrieve the attachment (the REST connector you configure in step 1), and then click the rule opener.
    4. In the MethodName field, select GET.
    5. In the ExecutionMode field, select Run.
    6. Click Add a step.
    7. In the Method field, press the Down arrow key and select Java.
    8. In the Method Parameters section, enter the following:
      tools.sendFile((byte[])myStepPage.getObject("Name_defined_in_response_clipboard_map_to_key "), "test.xls", false, null, true);
      where ("Name_defined_in_response_clipboard_map_to_key") is the map to key property that you enter in step 1c.
    9. Click Save.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

Contact us