Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JSON format in 10.1

    SmartClient_v101p_2016-02-28_PowerEdition

    REPRO steps
    ============
    1. Load the test case
    2. Execute exportJSON() in the console
    3. Observe JSON is not formatted nicely

    This worked in our previous SMartClient release (9.1). I am assuming that if the default behavior was changed, that there is a setting on the grid or JSONEncode that I can set to maintain the formatting (line breaks, indentation).



    Code:
    <!DOCTYPE html>
    
    <html>
    <head>
        <title ></title>
        
        <style>
                .diagInfo {
                    font-size: 14px;
                    font-weight: bold;
                    padding: 5px;
                }
            </style>
            
           <script type="text/javascript" >
            var isomorphicDir="http://localhost:8080/isomorphic/";
    
            
                
    </script>
        
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Core.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Foundation.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Containers.js"></script>
      <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Grids.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Forms.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_DataBinding.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Drawing.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_PluginBridges.js"></script> 
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic//system/modules/ISC_Charts.js"></script>
     <script type="text/javascript" SRC="http://localhost:8080/isomorphic/skins/EnterpriseBlue/load_skin.js"></script>
    
    </head>
    <body>
    
     <script type="text/javascript">
    
        var data = [
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 56, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 231, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Staples", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 12, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Staples", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 12, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Staples", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 12, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Staples", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 12, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Staples", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 12, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Staples", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 231, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"ABC Drywall Incorporated", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 12, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Google", building:"Warehouse", inspector: "Josh Burns" },
                { project: "123 Avenue", redflag: "", owner: "University of MD", ins: 33, obs: 2, unsafe: 9, safe: 222, insDate: "10/12/2011", score:"<img src='star-4.png'/>55%", score:"<img src='star-4.png'/>55%", link:"<a href=''>View Analysis</a>", company:"Google", building:"Warehouse", inspector: "Josh Burns" }
                
            ];
    
            // ===== DO NOT REMOVE =====
                var diagLabel = isc.Label.create({
                            ID: "diagInfo",
                            width: "100%",
                            styleName: "diagInfo",
                            autoFit: true
                        });
                // ===== DO NOT REMOVE =====
    </script>
    
    </head>
    
    <body>
    
        <script type="text/javascript">
        // set this to the correct JIRA ticket
                var JIRA_TICKET = "SNQA-1170";
                
        // once page loads set some diagnostic information, DO NOT CHANGE
                isc.Page.setEvent("load", function() {
                    document.title = JIRA_TICKET + "   (SmartClient version " + isc.versionNumber + ")";
                    var html = [];
                    html.push("Jira: " + JIRA_TICKET);
                    html.push("SmartClient: " + isc.versionNumber);
                    html.push("Browser: " + navigator.appCodeName + " " + navigator.appName + " " + navigator.appVersion);
                    diagLabel.setContents( html.join("<br>"));
                });
                
        isc.DataSource.create({
                ID: "ds",
                cacheData:data,
                clientOnly: true
            });
            
            var grid = isc.ListGrid.create({
                dataSource : ds,
                fields: [
                    {name:"project", title:"Project", type:"text" },
                    {name:"redflag", type:"text", title:"Flag"},
                    {name:"owner", type:"text", title:"Owner"},
                    {name:"ins", type:"integer", title:"#Inspections"},
                    {name:"obs", type:"integer", title:"#Observations",
                        summaryFunction: function(records, summaryField) {
    
                        var val = isc.SimpleType.applySummaryFunction(records,
                                summaryField, "sum");
                        if (typeof (val) != "undefined" && val != null) {
                            var num = new Number(val);
                            num = num.toFixed(2);
                            return num;
                        }
                        else {
                            return "NA";
                        }
                        }
                    },
                    {name:"unsafe", type:"integer", title:"# Non-Compliant"},
                    {name:"safe", type:"integer", title:"# Compliant"},
                    {name:"insDate", type:"date", title:"Last Inspection"},
                    {name:"company", type:"text", title:"Company"},
                    {name:"building", type:"text", title:"Building"},
                    {name:"inspector", type:"text", title:"Inspector"}
                ],
                dataFetchMode : "local",
                autoFetchData: true,
                width : 800,
                align : "center",
                autoDraw: false,
                autoFitData : "vertical",
                autoFitMaxHeight : 600,
                alternateRecordStyles : true,
                canAddFormulaFields : true,
                //canAddSummaryFields : true,
                canGroupBy : true,
                //canReorderFields : true,
                showGroupSummary : true,
                //groupByMaxRecords : 1000,
                //canMultiGroup : true,
                useAdvancedFieldPicker : true,
                advancedFieldPickerThreshold : 3,
                canEditTitles: true
            });
            
            var layout = isc.VLayout.create({
                    width:"100%",
                    membersMargin: 20,
                    members: [
                        // ===== DO NOT REMOVE diagLabel
                        diagLabel,
                        // ===== place anty components here
                        grid
                    ]
                });
                
                var exportJSON = function() {
                    exportOpts = {
                            exportAs : "json",
                            exportDisplay : "download",
                            exportFilename : "test.json"
                        };
                        
                        grid.exportClientData(exportOpts);
                }
    
                </script>
    </body>
    
    </html>

    #2
    Your code as written results in a CSV export, not a JSON export, because JSON exports aren't allowed by default for a client request. Is it possible that what you described as JSON that is "not formatted nicely" is really CSV?

    To allow JSON export (assuming you have already considered the security implications), you need to set operationBinding.exportAs in your .ds.xml file to allow it. The docs for listGrid.exportClientData() explain how to get a client export to go through a specific operationBinding.

    Comment


      #3
      Has this changed in 10.1? In 9.1 we exported using the code above and it resulted in a formatted, valid json output. Our users then uses that output to import into other tools. In 10.1 I may be seeing csv, but that would be a change from 9.1 and a breaking change.

      Please try the test case in 9.1 and you will see the json output.

      Comment


        #4
        Yes, 9.1 had a bug where JSON would be allowed for client requests, even though this is documented as not allowed and the server would output a warning saying that CSV would be used instead. That's about to be corrected.

        Comment


          #5
          Please point me to the 9.1 documentation for json not being allowed so I can add it to my release notes. Thanks.

          Comment


            #6
            Note that for security reasons, an export initiated using dsRequest properties does not provide support for JSON format (see this post for more detail).
            From dsRequest.exportResults.

            Comment

            Working...
            X