metric value as undefined in java scripts

we have a requirement to capture String type data from investigator and parse the data to format new metric. however we get "underfined " value from metricData.timeslicedValue.value function. we're not sure why. any clue ?

here is my function ( removed other js fuctions from the script to make it short)