Wednesday, December 22, 2021

 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

}


Example123e4567-e89b-12d3-a456-426614174000

(or)

import com.sap.it.api.mapping.*;

def String getUUID(String header, MappingContext context)
{
    return UUID.randomUUID().toString();
}   


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

}

Example123E4567E89B12D3A456426614174000


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 






Example:

UUID:123e4567-e89b-12d3-a456-426614174000

ID:123E4567E89B12D3A456426614174000

No comments:

Post a Comment

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field.

The sender will pass the data in JSON format without converting it to XML format. We need to read the particular field to check the conditio...