How to Simultaneously Output the Same Document via Email and via Printer

Scenario: The business have made a request for the delivery note to not only be emailed to the M3 user but also to be printed to a particular office printer.

Currently the delivery note (MMS480PF) is emailed to a particular M3 user via the following runtime configuration (Figure 1):

code6
Figure 1: Runtime configuration for an EMAIL-only Delivery Note
  1. Open the Message
  2. Change the name fof the Delivery_Note process to EMAIL_Delivery_Note
  3. Copy the EMAIL_Delivery_Note process
  4. Paste the copied process and rename it Printer_Delivery_Note
  5. Right click on the Printer_Delivery_Note process and select Script…
  6. Insert the following code:

setdestpath("PrinterName"); //for more info on this click here

  1. Open the Runtime
  2. Right-click on each process node and select Settings…
  3. Uncheck the Select automatically checkbox
  4. Connect the new Printer_Delivery_Note process node to your Printer output connector (mine is named PCL6
    • The EMAIL_Delivery_Note process node should be alreadyu connected to the MAIL output connector
  5. Right-click on the each process node and select Connector Selection…
  6. Select the Variable Connection Type and enter a variable name (see Figure 2)
code7
Figure 2
  1. Make sure that the Default Connector is the PCL6 output connector for the new Printer_Delivery_Note process node and MAIL for the EMAIL_Delivery_Note process node (see Figure 3)
code8
Figure 3: Runtime configuration for an Emailed AND printed document
  1. Open the Message
  2. Right-click on the message node and select Script…
  3. Insert the following code:

$SelectedOutputConnector = “MAIL”;
CallProc(“EMAIL_Delivery_Note”);
$SelectedOutputConnector = “PCL6”;
CallProc(“Printer_Delivery_Note”);

Export and deploy and test!

Troubleshoot: Control Center Producing the Fatal error: OutputMode set to Document or Job mode and current Message does not belong to a Job definition. (Connector):MAIL

Explanation: You are deploying an export but the referenced output connector in your message script does not match the selected output connector in your runtime.

  1. Open the message and right-click on the message icon and select Script…
  2. Examine the script and identify the output connector being referenced in the runtime. Figure 1 displays the MAIL output connect being called in our example.
code3
Figure 1: The message script
  1. Open the runtime examine the connection between the process (e.g. Invoice) and the output connector.
  2. You need to ensure that the process is referencing the correct output connector. Right-click on the process and select Connector Selection… Figure 2 shows that the process Invoice is referencing the correct MAIL output connector.
code2
Figure 2: The connector selection method

Export, deploy and test!

How to control the display of a label based on the value of a spool-field

SCENARIO: Some of your customers require their VAT number to be displayed on the invoice document. Your M3 customer master file only has the VAT number for several customers however you do not want to have the label VAT Number appearing with no accompanying value on an invoice.

  1. Open the OIS1990H event and transform the spool-field 0HWYVRNO into a variable 
  2. Open the PageOut and insert a Static Text object (this will be your label) to your canvas
  3. Rename the label to VAT Number
  4. In the Message window, collapse the Variable folder and drag the variable $0HWYVRNO to your canvasto the right/below of the label.
34
Figure 1: The Variable folder on the PageOut canvas
  1. Right-click on the label and select Edit Script…
  2. Insert the following code:

    if ($0HWYVRNO = “”) {
    skip();
    }
    else {
    {}
    }

The label VAT Number will now only appear if a value exists for the spool-field 0HWYVRNO. If the spool-field 0HWYVRNO value is blank then the label will be skipped (i.e. not appear).

Export and deploy and test!

How to output all subsequent characters following a particular character in a string

Scenario: You have to output all the subsequent characters following the ‘-‘ character of a field value coming from a datastream however, the string length of the value can vary from 3 characters on-wards, i.e.  the value is never fixed.

    1. Open the process.
    2. Add the variable version of the field you wish to format.
    3. Right-click on the variable and select Edit Script…
    4. Insert the following code:

    $a = $lotnumber;

    //searches string of $a for ‘-‘ and gets a position number
    $b=stridx($a,”-“);

    //adds 1 to the ‘-‘ position number to get next position
    $c = num($b)+ 1;

    //gets substring starting at ‘next’ position
    $lotnumber = substr($lotnumber,$c);

    1. Click OK.

    Export, deploy and test!

    • If the field value is 1234-567 you will output 567
    • IF the field value is -123 you will output 123
    • If the field value is 34-4533345689 you will output 4533345689

How to output the final x number of characters in a variable-length string

Scenario: You have to output the final three characters of a field value coming from a datastream however, the string of the value can vary from 3 characters on-wards, i.e.  the value is never fixed.

    1. Open the process.
    2. Add the variable version of the field you wish to format.
    3. Right-click on the variable and select Edit Script…
    4. Insert the following code:

    //Places the length of the string into variable $a
    $a=strlen($1MWWBANO);

    // Subtracts 2 from the length
    $b = num($a) – 2;

    //Variable $1MWWBANO takes the substring of its value based on the subtracted //variable $b as the position and ‘3’ as the number of subsequent places that are //outputted
    $1MWWBANO = substr($1MWWBANO,$b,3);

    1. Click OK.

    Export, deploy and test!

    • If the field value is 1234567 you will output 567
    • IF the field value is 123 you will output 123
    • If the field value is 34-4533345689 you will output 689

 

Scenario: How to count the quantity of pallets on a delivery note …

PREREQUISITE: You must have a policy of 1 pallet per delivery line (1L block) in the Delivery Note (MMS480PF) spool file.

  1. Open the PageOut process insert the variable $countlines outside of the frame. 

TIP: Place the variable on the First page and/or the Last page. 

  1. Insert the following code:

    $countlines = msgCountID(“MMS4801L”);

The total quantity of 1L block instances will now display thus displaying the amount of pallets on the delivery.

Export and deploy and test!

How to run a particular process (Method 2) …

TIP: Use this method in conjunction with an if statement which will determine the particular process based on a particular condition – click here to see a tutorial for this

  1. Open the runtime and uncheck the Select automatically checkbox for all the processes.
  2. Open the message and right-click on the message icon (circled in Figure 2) and select Script…

Figure 1 illustrates the runtime configuration.

5
Figure 1: Runtime Configuration

 

Figure 2 displays the message interface.

6
Figure 2: Message Interface
  1. Insert the following code:

CallProc(“Purchase_Order_v1.1”);

Export, deploy and test!