CA Service Management

 View Only

SPEL How to Execute Remote Reference via Perl code 

Jun 10, 2016 05:52 AM

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.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


0 Favorited
1 Files
zip file   1 KB   1 version
Uploaded - May 29, 2019

Tags and Keywords


Jan 09, 2017 11:02 AM

Thank you for the reply.


Run fine 

my $customer_uuid = pUUID::string($customer);


Jan 09, 2017 10:10 AM


try this one:


my $customer_uuid = UUID::string($customer);


my $customer_uuid = pUUID::string($customer);

Jan 09, 2017 08:09 AM



I'm interested in this solution, but I need get the uuid customer and assigned as a string. How can I do this?



my $customer=$obj->getval("customer");

my $comando = 'echo -n '. $refnum . '-' . $idcr . '-' . $customer . ' | md5sum'

but when I viewed the line i get "pUUID=SCALAR(0x8fff11c)" in $customer, i tried to change customer by and customer.persistent_id but spel srvc was crashed.



Sep 12, 2016 05:59 AM

Could you please share an example how to call Java using RPC daemon?

Sep 12, 2016 04:26 AM

To execute java code, it is better to call java direct in spell over the rpc deamon. So, you have the same functionality, like the shown method from Gutis. Execute Spell Code -> Call Java -> Do some stuff in Java -> Return Result to Spell Code

Sep 02, 2016 05:00 PM


#I changed the source code refering new modules PERL:

use Encode;
use utf8;


#And added new lines to convert UTF-8 to CP1252;

    my $cmd = "c:/ca/sdm/temp/a.bat";

    my $code_points = decode('UTF-8', $cmd);
    $cmd = encode('cp1252', $code_points);


    my $captured = `$cmd 2>&1`;
    my $errorcode = $? >> 8;



Sep 02, 2016 08:31 AM


The problem is not only incorrect display of characters. The fact is that PERL method is converting characters in parameters informed when they have special characters. I emphasize that this problem does NOT occur when I run the call using only the native SPEL method " exec" .

Sep 01, 2016 04:46 PM

My previous post most probably will not help, but  You may also try to change default encoding of the console to 860 or 65001

  1. Go to [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\Autorun]
  2. Change the value to chcp 860 >null

Sep 01, 2016 04:30 PM

I do not have possibility to test, but you may try to use bat file in order to set command prompt encoding before executing java program.

Something like this


chcp 860

yourjavaprogram param1

Sep 01, 2016 03:29 PM

Hi guys,
I am facing a issue with character encoding when I run this PERL method to execute a shell call.
I use a method SPEL riding a command line (Ex .: Java.exe + parameters) with specific parameters
derived attributes of an object (Ex.: summary on the object cr). The problem occurs when this "summary"
attribute has special characters (Ex .: ç).
When the call is made, instead of running out to be in UTF-8, PERL method forces the conversion to
ANSI (cp1252) resulting in caracterer "ç".
On the other hand if I run this same shell with the native method SPEL "exec" works perfectly.
I know PERL has encoding and decoding methods "charset", but I dont found a solution to this case.
Does anyone know how to solve this problem?
Thank you very much.

Related Entries and Links

No Related Resource entered.