Hi Chaitanya
I just tried this and … it works for me!
I suspect you’re having trouble encoding and storing the value.
I have stored in the KVM a value with a \n. I did this via the API… When I invoke the API call, the string contains a slash character, followed by a n character. It looks like this:
curl -X POST $mgmtserver/v1/o/$org/e/$env/keyvaluemaps/$mapname/entries/test-key -H content-type:application/json -d '{
"name" : "test-key",
"value" : "test-value 20170803-144830\nThis is line #2\nThis is line #3"
}'
Then, in the API proxy, I include a KVM Get policy configured like so:
<KeyValueMapOperations name="KVM-Get-1" mapIdentifier="NonSecrets">
<DisplayName>KVM-Get-1</DisplayName>
<ExpiryTimeInSecs>10</ExpiryTimeInSecs>
<Get assignTo="myVariable">
<Key>
<Parameter>test-key</Parameter>
</Key>
</Get>
<Scope>environment</Scope>
</KeyValueMapOperations>
And then in the response flow, I have an AssignMessage policy, configured like this:
<AssignMessage name="Assign-Message-1">
<DisplayName>Assign Message-1</DisplayName>
<Remove>
<Headers/>
</Remove>
<Set>
<Payload contentType="text/plain">{myVariable}</Payload>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>
The output is like this:
$ curl -i [https://${org}-${env}.apigee.net/retrieve-kvm-multiline](https://${org}-${env}.apigee.net/retrieve-kvm-multiline)
HTTP/1.1 200 OK
Date: Thu, 03 Aug 2017 21:46:29 GMT
Content-Type: text/plain
Content-Length: 58
Connection: keep-alive
Server: Apigee Router
test-value 20170803-144830
This is line #2
This is line #3
This shows that multiple lines are in the retrieved value.
When I run a JS callout like this:
var value = context.getVariable('myVariable');
var lines = value.split('\n');
context.setVariable('line_count', lines.length.toFixed(0));
…the line_count variable gets the value ‘3’. This shows that the JS callout “sees” the multiple lines.
There is one problem - the Apigee Edge UI does not properly show the newlines in the Web page.

This is a UI bug. But at runtime it behaves properly.