JSON
Posted by Sebastian Haugland - Oct 21 ’15 at 04:28
Hi
I have made a HTML with the contens below (the button is not in use yet)
It works fine as it is below but I want to make it dynamical ie change
THIS: obj = {"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567","MC":"Yes"};
to THIS var obj=fd.field('JSON').value();ie read into obj from a sharepoint list multiline field, but it does not work - any suggestions?
MY HTML:
<!DOCTYPE html>
<html>
<body>
<h2>JSON Object Creation in JavaScript</h2>
<button onclick="hh()">JSON</button>
<p id="demo3"></p>
<script>
obj = {"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567","MC":"Yes"};
//var obj=fd.field('JSON').value();
document.getElementById("demo3").innerHTML =
obj.name + "<br>" +
obj.street + "<br>" +
obj.MC + "<br>" +
obj.phone;
</script>
</body>
</html>
-
rostislavModeratorMember for: 7 years 1 month 19 days
Hello! If your field is a multiline plain text field, then yes, that's how you'd retrieve the value. The only thing that's left to do is parse the string value into an object, like this:
var obj = JSON.parse(fd.field('JSON').value());
-
Sebastian HauglandMemberMember for: 7 years 3 months 2 days
Thanks but I still can make it work for a multiline field - it works for a single line text field
-
Sebastian HauglandMemberMember for: 7 years 3 months 2 days
[#2]: Thanks but I still can't get it to work for a multiline field - it works for a single line text field
-
rostislavModeratorMember for: 7 years 1 month 19 days
[#3]:
The term "multiline text field" is ambiguous in SharePoint 2010. There are at least three types. The way you're accessing it would work for a plain multiline text field, but not for the other two. Refer to this page to see how to access a field with regards to its type http://formsdesigner.blogspot.com/2013/04/getting-and-setting-sharepoint-form.html
If indeed you're trying to access a multiline plain text field then we can schedule a Team Viewer session to sort out your problem.
-
Sebastian HauglandMemberMember for: 7 years 3 months 2 days
[#4]: Yes... but working now
I wanted a mulitline field to be able to store (JSON) more than 255 chars, but as I mention it did not work - but after I changed the field from 6 lines of editing (standard) to 1 line in Sharepoint it works