Random UUID generator in SAP CPI using Groovy Scripts
Assign constant and add the groovy script in Message Mapping and map the UUID field it will randomly generate UUID in SAP CPI.
Constant->Script->UUID field
Groovy Scripts:
import com.sap.it.api.mapping.*;
def String customFunc(String arg1)
{
def randomID = UUID.randomUUID().toString();
return randomID
}
Example: 123e4567-e89b-12d3-a456-426614174000
(or)
import com.sap.it.api.mapping.*;
def String getUUID(String header, MappingContext context)
{
return UUID.randomUUID().toString();
}
Example: 123e4567-e89b-12d3-a456-426614174000
(or)
import com.sap.it.api.mapping.*;
def String customFunc(String arg1){
def randomID = UUID.randomUUID().toString().replace("-", "").toUpperCase();
return randomID
}
Example: 123E4567E89B12D3A456426614174000
Generate Random UUID & ID Using Groovy Scripts and Node Function :
Instead of using two groovy scripts for UUID and ID ,We can use the below method .
we will generate UUID using groovy script and then use node function to pass UUID to ID
UUID:123e4567-e89b-12d3-a456-426614174000
ID:123E4567E89B12D3A456426614174000