JSON

rss

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>

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 3 months 12 days
    #1 by rostislav Oct 22 ’15 at 04:03

    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 Haugland
    Sebastian Haugland
    Member
    Member for: 4 years 4 months 25 days
    #2 by Sebastian Haugland Oct 22 ’15 at 08:01

    Thanks but I still can make it work for a multiline field - it works for a single line text field

  • Sebastian Haugland
    Sebastian Haugland
    Member
    Member for: 4 years 4 months 25 days
    #3 by Sebastian Haugland Oct 22 ’15 at 08:03

    [#2]: Thanks but I still can't get it to work for a multiline field - it works for a single line text field

  • rostislav
    rostislav
    Moderator
    Member for: 4 years 3 months 12 days
    #4 by rostislav Oct 22 ’15 at 11:07

    [#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 Haugland
    Sebastian Haugland
    Member
    Member for: 4 years 4 months 25 days
    #5 by Sebastian Haugland Oct 26 ’15 at 10:25

    [#4]: Yes... but working now smile 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 smile

Displaying 1 to 5 of 5 messages