Technical Articles
SAP Build Process Automation’s Little Technique – Datatype Conversion
How to convert data types?
In SAP Build Process Automation, we design forms by placing fields of string and numeric types. I sometimes encounter situations where I wish I could convert the data type.
For example, let’s consider the following form in an expense application flow

I may want to use the numeric value of the amount entered on this form for the Subject of the approval request to the approver, such as “You have a $1000 expense approval request received”. If you actually try to do this, you will have to do the following.
It is not possible to set a value of numeric type in this Subject field.
There may be other similar situations. Many of you may have wished you could convert the data type from numeric to string.
What should we do? Here are two methods.
1. Use Automation
First, set up the Automation input and output as follows




2. Use Action
var express = require("express");
var router = express();
var cors = require("cors");
// Allow CORS
router.use(cors());
router.use(express.json());
router.post('/numbertostring', (req, res) => {
console.log("numbertostring in");
console.log("Value="+ req.body.input);
var returnvalue={};
returnvalue.returnvalue = String(req.body.input);
res.json(returnvalue);
})
router.post('/stringtonumber', (req, res) => {
console.log("stringtonumber in");
console.log("Value="+ req.body.input);
var returnvalue={};
//NOTE : This part should originally describe the logic for the case where conversion to a numeric type is not possible.
returnvalue.returnvalue = Number(req.body.input);
res.json(returnvalue);
})
router.listen(process.env.PORT || 4000);
To make this available to Action, use the following Open API definition.
{
"openapi": "3.0.0",
"info": {
"title": "String to Number and Number to String Converter",
"version": "1.0.0",
"description": "A sample API to convert string to number and number to string."
},
"paths": {
"/stringtonumber": {
"post": {
"summary": "Converts a string to a number",
"requestBody": {
"description": "Input JSON object containing the string to be converted to a number",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "string",
"example": "123"
}
},
"required": ["input"]
}
}
}
},
"responses": {
"200": {
"description": "Successful response with the converted number",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"returnvalue": {
"type": "number",
"example": 123
}
}
}
}
}
}
}
}
},
"/numbertostring": {
"post": {
"summary": "Converts a number to a string",
"requestBody": {
"description": "Input JSON object containing the number to be converted to a string",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "number",
"example": 123
}
},
"required": ["input"]
}
}
}
},
"responses": {
"200": {
"description": "Successful response with the converted string",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"returnvalue": {
"type": "string",
"example": "123"
}
}
}
}
}
}
}
}
}
}
}
This Action can be used to convert numeric types to string types.