please add basic sample

May 31, 2010 at 11:43 AM

Hello,

I am a beginner in jPoint

And I would like to retrieve content from a calendar

to begin, I try to retrieve data from a List

it looks like Webservice would be a good way to retrieve data

If I call

var myjLocalOptions={SiteURL:'https://www.compagny.com/TestJpoint/',ListName:'TestCalendar'};
yiyi = jP.WebServices.GetList(myjLocalOptions);
--> I have an Error GUID


If I call
yiyi = jP.WebServices.GetWeb(myjLocalOptions) /* without listname*/
--> It works but I don't know what to do with my var yiyi to retrieve List and then object List

You should but a basic sample code for each method

Kind Regards

 

Coordinator
Jun 1, 2010 at 4:17 PM
Edited Jun 1, 2010 at 5:16 PM
Here's a snippet of how I've used it. Basically use getSPItemsWithQuery and query need to filter by begin and end dates.
    function ProcessCalendarEvents() {
        var curSite = "/path/sitename";
        var curCalendar = "calendarlistname";
        var dt = new Date();
        var year = dt.getFullYear();
        var month = dt.getMonth();
        var date = 1;
        var status = "ACTIVE";
        var fields = ["Title","EventDate","FileRef","ID"];
        var events = getCalendarEvents(curSite, curCalendar, fields, year, month, date, status);
        //process events data here
    }
    function getCalendarEvents(siteurl, listname, fields, year, month, date, status) {
        if (typeof date != "undefined") {
            var dt = new Date(year, month, date);
            var sdate = dt.getFullYear() + "-" + (dt.getMonth()+1) + "-" + dt.getDate();
            var startDate = sdate;
            var endDate = sdate;
        }
        else {
            var lastdt = new Date(year, month, 1);
            lastdt.setDate(lastdt.getDate()-1)
            var firstdt = new Date(year, month-1, 1);
            firstdt.setDate(firstdt.getDate()-1)
            var startDate = firstdt.getFullYear() + "-" + (firstdt.getMonth()+1) + "-" + firstdt.getDate();
            var endDate = lastdt.getFullYear() + "-" + (lastdt.getMonth()+1) + "-" + lastdt.getDate();
        }
        var FullSiteURL = document.location.protocol + "//" + document.location.host + siteurl;
        var spl = jP.Lists.setSPObject(FullSiteURL, listname);     
        //var listobj = spl.getSPListFields(); //get schema    
        var qry1 = "<And>"
        qry1 += "<Geq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='FALSE'>" + startDate + "</Value></Geq>"
        qry1 += "<Leq><FieldRef Name='EventDate' /><Value Type='DateTime' IncludeTimeValue='FALSE'>" + endDate + "</Value></Leq>"
        qry1 += "</And>"
        var qry2 = "<And>"
        qry2 += "<Eq><FieldRef Name='Status' /><Value Type='Text'>" + status + "</Value></Eq>";
        qry2 += qry1;
        qry2 += "</And>"

        qry = "<Where>"
        if (typeof status != "undefined")
            qry += qry2;
        else
            qry += qry1;           
        qry += "</Where>";     
        qry += "<OrderBy><FieldRef Name='EventDate' Ascending='TRUE' /></OrderBy>";
        spl.getSPItemsWithQuery(qry); //get by query       
        var data = spl.JQueryData;
        var events = getAttrs(data, fields);
        return events;
    }
    getAttrs = function (data, names) {
        var res = [];
        $.each(data, function(i, row){
            var attrs = $(row).get(0).attributes;
            var dset = {};
            for(var i=0;i<names.length;i++) {
                dset[names[i]] = that.getAttrValue(attrs, names[i]);
            }
            //res.push({text:names[0],value:val0});
            res.push(dset)
        });
        return res;
    }
    getAttrValue = function (attrs, attr)
    {
        var res = "";
        attr = attr.toUpperCase();
        $(attrs).each(function(j, attrItem){
        var attrName = this.name.replace(/ows_/i, "").replace(/_/, "").toUpperCase();
        var attrValue = this.value;
        if(attrName == attr) {
            //res = escape(attrValue.replace(/[\r\n]/g,""));
            res = attrValue.replace(/[\r\n]/g,"");
            if (res.indexOf(";#")>0)
                res = res.split(";#")[1];
            }
        });
        return res;
    }
 
Jun 1, 2010 at 7:06 PM
Edited Jun 1, 2010 at 7:08 PM

Thanks for your sample

 

I also found

http://www.sharejpoint.com/src/jPoint/Test/jPWSInspector.js
and
http://www.sharejpoint.com/src/jPoint/webparts/jPListInspector.js

in your site and it helps me a lot to undertstand how it is suppose to work

You should really paste a small sample in the doc for each method (an extract of the inspector would be Ok I think)

However nice library

 

PS During my test,I Use

var spl = jP.Lists.setSPObject(FullSiteURL, listname);

in fact it looks like setSPObject don't need a fullSiteUrl