Skip to Content
Technical Articles

How to pass complex object in process between two desktop packages

This documentation explain that you can reuse and combine two different desktop packages with process. But for now, there is a limitation, you can pass only primitive parameters from a desktop package scenario to another.

In this blog post I will explain how to surpass this limitation.

Actually, there is a way to pass complex parameters if you serialize your object before sending it in output and unserialize your input parameters. Let’s see how to do this.

1 – Create your desktop packages

For this blog post I have created two simple projects. The first one sends a mathematical operation in output parameters and the second received this operation and execute it.

SendOperation project

As mentioned, this project will only send some parameters.

Context creation

The first thing to do is to define the data context of the workflow.

In this context there is:

  • outputData : we will put the serilization of our object in this attribute and it will be the output of the workflow.
  • OperationData : A complex object that contain 3 attributes
    • FirstNumber
    • Operator
    • secondNumber

Workflow creation and configuration

Now you can create your workflow, but before adding any activity you have to configure the context like this:

Here the Input Data Manager is the context created and the output is the field outputData.

Workflow content

This workflow is very simple, only two custom steps are enough:

The first one is to initialize the data and the second serialize OperationData and put it into outputData.

Here is the code :

// ----------------------------------------------------------------
//   Step: Init_Operation_Data
// ----------------------------------------------------------------
GLOBAL.step({ Init_Operation_Data: function(ev, sc, st) {
	var rootData_SendOperationData = sc.data;
	ctx.workflow('scSendOperation', 'f1d90ff3-e30f-49a9-85f6-1392c1e08411') ;
	// Describe functionality to be implemented in JavaScript later in the project.
	rootData_SendOperationData.OperationData.firstNumber = 21;
	rootData_SendOperationData.OperationData.operator = "x";
	rootData_SendOperationData.OperationData.secondNumber = 2;
	sc.endStep(); // Serialize_parameters
	return;
}});

// ----------------------------------------------------------------
//   Step: Serialize_parameters
// ----------------------------------------------------------------
GLOBAL.step({ Serialize_parameters: function(ev, sc, st) {
	var rootData_SendOperationData = sc.data;
	ctx.workflow('scSendOperation', '0a684bc2-4c65-4f5f-a20f-bca6c0a929dd') ;
	// Describe functionality to be implemented in JavaScript later in the project.
	rootData_SendOperationData.outputData = ctx.json.stringify(rootData_SendOperationData.OperationData);
	sc.endStep(); // end Scenario
	return;
}});

The interesting part is the second step, we use a SDK function to serialize the objet. Thanks to this we have a string that we can send in output.

Calculator project

The second workflow will deserialize the input parameter and execute the operation, the result will put the output of the workflow.

Context creation

We have to define the context for this workflow before doing anything:

  • Input : the input data of the workflow, it will contain the output of the SendOperation workflow
  • Output : we will set the result of the operation in this attribute
  • CalculationData : The complex type that contain the 3 attribute of the operation
    • firstNumber
    • operator
    • secondNumber

Workflow creation and configuration

Now you can create your workflow, but before adding any activity you have to configure the context like this:

Here the Input Data Manager is the context created and the output is the field output and the input of the workflow is the input attribute.

 Workflow content

In this workflow also we have only two simple custom steps:

The first one is to unserialize the parameters and the second one to execute the operation.

Here is the code of the steps:

// ----------------------------------------------------------------
//   Step: Unserialize_parameter
// ----------------------------------------------------------------
GLOBAL.step({ Unserialize_parameter: function(ev, sc, st) {
	var rootData_CalculatorData = sc.data;
	ctx.workflow('scCalculator', 'c2f7371a-b3cf-422b-810e-7c3d458dffa2') ;
	// Describe functionality to be implemented in JavaScript later in the project.
	rootData_CalculatorData.CalculationData = ctx.json.parse(rootData_CalculatorData.input);
	
	sc.endStep(); // Calculate
	return;
}});

// ----------------------------------------------------------------
//   Step: Calculate
// ----------------------------------------------------------------
GLOBAL.step({ Calculate: function(ev, sc, st) {
	var rootData_CalculatorData = sc.data;
	ctx.workflow('scCalculator', '7a46ce02-0643-4614-afbd-e5a69f6f92e0') ;
	// Describe functionality to be implemented in JavaScript later in the project.
	switch(rootData_CalculatorData.CalculationData.operator){
		case "x":
			rootData_CalculatorData.output = rootData_CalculatorData.CalculationData.firstNumber * rootData_CalculatorData.CalculationData.secondNumber;
			break;
		case "+":
			rootData_CalculatorData.output = rootData_CalculatorData.CalculationData.firstNumber + rootData_CalculatorData.CalculationData.secondNumber;
			break;
		case "-":
			rootData_CalculatorData.output = rootData_CalculatorData.CalculationData.firstNumber - rootData_CalculatorData.CalculationData.secondNumber;
			break;
		case "/":
			rootData_CalculatorData.output = rootData_CalculatorData.CalculationData.firstNumber / rootData_CalculatorData.CalculationData.secondNumber;
			break;
		default :
			rootData_CalculatorData.output = "Operator not defined";
	}
	sc.endStep(); // end Scenario
	return;
}});

2 – Create the process

Now that you have you two projects, we can create the process that will combine the two packages.

Before the process create you have to export the packages with the Desktop Studio.

Once you have done this you just have to create a new project in the factory:

 

Then import your 2 desktop packages in your cloud project.

Then you have to make each workflow that you will use as skill:

Once you have done this you can create your process using the menu Create => Process

Then, you can drag and drop scSendOperation and scCalulator in your process:

The last thing that you have to do is to set outputData as input parameters of scCalculator.

And it’s done! Now you can schedule your process and test it.

 

Conclusion

The Cloud Studio doesn’t provide a way to use complex parameter, but with this technic you are able to use Desktop Studio complex parameters in a process.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.