SPEL How to Execute Remote Reference via Perl code

Document created by Gutis Champion on Jun 10, 2016Last modified by Gutis Champion on Aug 23, 2016
Version 2Show Document
  • View in full screen mode

This document describes how to execute remote reference and get response from it by the means of Spel code.

Here is the process that describes algorithm in general


This example execute Perl code from Spel on status change and puts summary, ref_num and bat file output to the description:


First of all we need to define spel method on some object as any other spel method. I have also defined trigger on cr object that will initiate the whole process





  POST_VALIDATE spel_function() 4015 FILTER(EVENT("UPDATE") && status{});







Now you need to define spell function to perl function


void cr::spel_function(...) {
 uuid who;  
 send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");  
 send_wait(0, this, "perl_function");
 string ret;
 ret = msg[0];
 logf(SIGNIFICANT, "Bat echo string %s, ref_num %s, summary %s ", msg[0], msg[1], msg[2]);

 send_wait(0, top_object(), "call_attr", "api", "update_object_super", who, persistent_id, 0, "description", format("Bat echo string %s, ref_num %s, summary %s ", msg[0], msg[1], msg[2]));  
 if (msg_error()) {  
    logf(ERROR,"Error %s",msg[0]);  


The final step is to create perl function that will execute bat file

use pdm_perlext;
use pdm_misc;
use strict;

sub cr::perl_function {

my $captured = `c:/ca/sdm/temp/a.bat 2>&1`;
# some more data for return data example
my $obj = this_object();
my $refnum=$obj->getval("ref_num");
my $summary=$obj->getval("summary");

# set_return_data(arg1, arg2, arg3, arg4):
# arg1 = datatype(as an integer)
# arg2 = data of the type declared above or data where an implicit cast to that type will succeed
# arg3 = Index number
# arg4 = count of indexes
# Multiple calls will push more returned values into the msg array
# 0 = nil (no arguments)
# 1 = object
# 4 = integer
# 8 = real
# 16 = string

set_return_data(16, $captured, 0, 3);
set_return_data(16, $summary, 2, 3);
set_return_data(16, $refnum, 1, 3);

# Perl modules must end with a statement that returns a true value


I have attached files for this example. To make it work you need to copy perl.pm, perl.spl and perl.mod to your site/majic directory and copy bat file to c:\ca\sdm\temp\a.bat

This example is for education purpose only. Please do not use it on your production enviroment!

Special thanks to all guys that managed to solve this in SpelMaster Event and to JussiValkonen for commments in .pm file


6 people found this helpful