简体   繁体   中英

Javascript to Read/Count Sharepoint 2010 List Items

I am having a lot of trouble with this. Essentially, I am trying to count the number of times Decommission appears in a particular list column. From what I can tell, the javascript is correct, but it doesn't work. Can anyone provide some guidance? Thanks!

<script type="text/javascript">
                        var myItems = null;
                        var siteUrl = &apos;https://chartiscorp.sp.ex3.secureserver.net/&apos;

                        function SuperDuper()
                        {
                            var queryString = &apos;<View><Query><Where><Gt><FieldRef name="End State" /><Value Type="String">Decommission</Value></Gt></Where></Query></View>&apos;;
                            var myContext = new SP.ClientContext(siteUrl);
                            var myWeb = myContext.get_web();
                            var myList = myWeb.get_lists().getByTitle(&apos;System_Information&apos;);
                            var myQuery = new SP.CamlQuery();

                            myQuery.set_viewXml(queryString);
                            myItems = myList.getItems(myQuery);

                            myContext.load(myItems,&apos;Includes(End State)&apos;);
                            myContext.executeQueryAsynch(Function.createDelegate(this,SuperDuperSuccess),Function.createDelegate(this,SuperDuperFail));
                        }

                        function SuperDuperFail(sender, args)
                        {
                            alert(&apos;Failed &apos; + args.get_message());
                        }

                        function SuperDuperSuccess(sender, args)
                        {
                            var endStateEnumerator = myItems.getEnumerator();
                            var decommCount = 0;

                            while(endStateEnumerator.moveNext())
                            {
                                //var currentEndState = endStateEnumerator.get_current();
                                decommCount = decommCount + 1;
                            }

                            alert(decommCount);
                        }   

                        window.onload = SuperDuper;
                    </script>

What is the error? Have you tried to see the script error it is throwing?

In function SuperDuperSuccess() you can simply put

 var count=0;
 count=this.myItems.get_count();

No need to write while loop .

Pls try to put alert and after some line and see what is coming.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM