Forum Discussion
ReshmaSachdev
13 years agoContributor
Hello,
You can use following script assuming that Active/Pending both nodes have status and date sub nodes in any case:
def response = context.expand( '${Request1#Response#declare namespace ns=\'whichever you have'; //ns:Response[1]/ns:status[1]}' )
holder = groovyUtils.getXmlHolder( "Request name to be used#Request" )
holder.namespaces["ns"] = "Name space to be used or whichever is available"
// Clearing prev values from both status and date
path = '//status'
holder.setNodeValue(path , '')
path = '//date'
holder.setNodeValue(path , '')
// Setting status and date as per response
if(response == 'P' || response == 'p')
{
path = "//search/pending/status"
holder.setNodeValue(path , "Pending")
path = "//search/pending/date"
date = new Date().format('YYYY-MM-DD')
holder.setNodeValue(path , date)
}
else if(response == 'A' || response == 'a')
{
path = "//search/active/status"
holder.setNodeValue(path , "Active")
path = "//search/active/date"
date = new Date().format('YYYY-MM-DD')
holder.setNodeValue(path , date)
}
Hope it helps...
You can use following script assuming that Active/Pending both nodes have status and date sub nodes in any case:
def response = context.expand( '${Request1#Response#declare namespace ns=\'whichever you have'; //ns:Response[1]/ns:status[1]}' )
holder = groovyUtils.getXmlHolder( "Request name to be used#Request" )
holder.namespaces["ns"] = "Name space to be used or whichever is available"
// Clearing prev values from both status and date
path = '//status'
holder.setNodeValue(path , '')
path = '//date'
holder.setNodeValue(path , '')
// Setting status and date as per response
if(response == 'P' || response == 'p')
{
path = "//search/pending/status"
holder.setNodeValue(path , "Pending")
path = "//search/pending/date"
date = new Date().format('YYYY-MM-DD')
holder.setNodeValue(path , date)
}
else if(response == 'A' || response == 'a')
{
path = "//search/active/status"
holder.setNodeValue(path , "Active")
path = "//search/active/date"
date = new Date().format('YYYY-MM-DD')
holder.setNodeValue(path , date)
}
Hope it helps...