eos: stock balance groovy 19th nov
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.util.XmlParser
import groovy.xml.XmlUtil
import com.sap.it.api.ITApiFactory
import com.sap.it.api.mapping.ValueMappingApi
def Message processData(Message message) {
// Get the body of the message as string
def body = message.getBody(java.lang.String) as String
// Parse the XML
def parser = new XmlParser()
def stockBalance = parser.parseText(body)
// Retrieve the value mapping API service
def valueMapApi = ITApiFactory.getService(ValueMappingApi.class, null)
// Iterate over each item in the items list
stockBalance.items.item.each { item ->
def wmsQualityStatus = item.wmsQualityStatus.text()
def qualityStatus = item.qualityStatus.text()
def positiveRelease = item.positiveRelease.text()
// Apply the additional logic
if (['BLC', 'DES', 'OBS', 'PEN', 'RET', 'SPE'].contains(wmsQualityStatus)) {
qualityStatus = '*'
positiveRelease = '*'
}
if (['HOLD', 'FSI', 'Disposal-Normal', 'Disposal-Special'].contains(qualityStatus)) {
wmsQualityStatus = '*'
positiveRelease = '*'
}
// Concatenate the values with a pipe and prepare sourceValue
def sourceValue = "${wmsQualityStatus}|${qualityStatus}|${positiveRelease}"
sourceValue=sourceValue.replaceFirst(/^0+/, '')
when ever we store value in valuemapping table, it saved as deleting leading zeros ,
after adding logic to my existing input , getting right value.
// Call the Value Mapping API to get the target value
def targetValue = valueMapApi.getMappedValue('Source', '3fieldsConcat', sourceValue, 'Target', 'fileType')
// Set the stockBalanceItemtype based on the target value received
if (targetValue) {
item.stockBalanceItemtype[0].value = targetValue
} else {
item.stockBalanceItemtype[0].value = 'Mapping Not Found' // Fallback if no mapping is found
}
}
// Convert the modified object back to XML string
def writer = new StringWriter()
def xmlOutput = new XmlUtil().serialize(stockBalance, writer)
// Set the modified XML back as the message body
message.setBody(writer.toString())
return message
}
----------------
16:46
import com.sap.gateway.ip.core.customdev.util.Message import groovy.util.XmlParser import groovy.xml.XmlUtil import com.sap.it.api.ITApiFactory import com.sap.it.api.mapping.ValueMappingApi def Message processData(Message message) { // Get the body of the message as string def body = message.getBody(java.lang.String) as String // Parse the XML def parser = new XmlParser() def stockBalance = parser.parseText(body) // Retrieve the value mapping API service def valueMapApi = ITApiFactory.getService(ValueMappingApi.class, null) // Iterate over each item in the items list stockBalance.items.item.each { item -> def wmsQualityStatus = item.wmsQualityStatus.text() def qualityStatus = item.qualityStatus.text() def positiveRelease = item.positiveRelease.text() // Apply the additional logic if (['BLC', 'DES', 'OBS', 'PEN', 'RET', 'SPE'].contains(wmsQualityStatus)) { qualityStatus = '*' positiveRelease = '*' } if (['HOLD', 'FSI', 'Disposal-Normal', 'Disposal-Special'].contains(qualityStatus)) { wmsQualityStatus = '*' positiveRelease = '*' } // Concatenate the values with a pipe and prepare sourceValue def sourceValue = "${wmsQualityStatus}|${qualityStatus}|${positiveRelease}" // Call the Value Mapping API to get the target value def targetValue = valueMapApi.getMappedValue('Source', '3fieldsConcat', sourceValue, 'Target', 'fileType') // Set the stockBalanceItemtype based on the target value received if (targetValue) { item.stockBalanceItemtype[0].value = targetValue } else { item.stockBalanceItemtype[0].value = 'Mapping Not Found' // Fallback if no mapping is found } } // Convert the modified object back to XML string def writer = new StringWriter() def xmlOutput = new XmlUtil().serialize(stockBalance, writer) // Set the modified XML back as the message body message.setBody(writer.toString()) return message }
---
19th nov 24 1646
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.util.XmlParser
import groovy.xml.XmlUtil
import com.sap.it.api.ITApiFactory
import com.sap.it.api.mapping.ValueMappingApi
def Message processData(Message message) {
// Get the body of the message as string
def body = message.getBody(java.lang.String) as String
// Parse the XML
def parser = new XmlParser()
def stockBalance = parser.parseText(body)
// Retrieve the value mapping API service
def valueMapApi = ITApiFactory.getService(ValueMappingApi.class, null)
// Iterate over each item in the items list
stockBalance.items.item.each { item ->
def wmsQualityStatus = item.wmsQualityStatus.text()
def qualityStatus = item.qualityStatus.text()
def positiveRelease = item.positiveRelease.text()
// Concatenate the values with a pipe and prepare sourceValue
def sourceValue = "${wmsQualityStatus}|${qualityStatus}|${positiveRelease}"
// Call the Value Mapping API to get the target value
//println sourceValue
def targetValue =valueMapApi.getMappedValue('Source', '3fieldsConcat', sourceValue, 'Target', 'fileType')
// Set the stockBalanceItemtype based on the target value received
if (targetValue) {
item.stockBalanceItemtype[0].value = targetValue
} else {
item.stockBalanceItemtype[0].value = 'Mapping Not Found' // Fallback if no mapping is found
}
//println targetValue
//println item.stockBalanceItemtype
/*
* HOLD * *|HOLD|*
* FSI * *|FSI|*
* Disposal-Normal * *|Disposal-Normal|*
* Disposal-Special * *|Disposal-Special|*
1 released Y 1|released|Y
1 released N 1|released|N
BLC * * BLC|*|*
DES * * DES|*|*
OBS * * OBS|*|*
PEN * * PEN|*|*
RET * * RET|*|*
SPE * * SPE|*|*
Blocked Stock
Blocked Stock
Blocked Stock
Blocked Stock
Available Stock On Hand
Non Available Stock On Hand
Blocked Stock
Blocked Stock
Blocked Stock
Blocked Stock
Blocked Stock
Blocked Stock*/
}
// Convert the modified object back to XML string
def writer = new StringWriter()
def xmlOutput = new XmlUtil().serialize(stockBalance, writer)
// Set the modified XML back as the message body
message.setBody(writer.toString())
return message
}