Update value of a field

Hi, I am running the groovy script from JAVA which is something like this

def value=DynamicValue
def Nvalue=NewValue
def field=Fieldvalue
def prod

NewValue=NewValue.toInteger()
prod=doc[''+DynamicValue+''].value*NewValue
if(doc[''+Fieldvalue+''].value != null)
{
doc[''+Fieldvalue+''].value=prod //here i am trying to update the field value
}

but when i am running the script i am getting an error like this

{
"took" : 211,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 2,
"failed" : 3,
"failures" : [ {
"shard" : 0,
"index" : "jdbcdata",
"node" : "u9hIkU7HQDWqLXOoFSoLuQ",
"reason" : {
"type" : "script_exception",
"reason" : "failed to run file script [fieldScript] using lang [groovy]",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "argument type mismatch"
}
}
} ]
}

How do i update the value of the field ????