Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

spservices different results in IE and Chrome.

Why is the following working in IE only?  It does not work in Chrome or firefox.  In firefox, I believe it has something to do with spservices.

/ JavaScript source code
$(document).ready(function () {
    SP.SOD.executeOrDelayUntilScriptLoaded(retrieveData, "sp.js");
    //'SP.ClientContext',
    itemProjectNumber = getQueryString('projNumber');

    //Check to see if project number exist. If so, change buttons to update from submit
    var itemIDPPD = getID(itemProjectNumber, "Procurement Plan (Design)");
    if (itemIDPPD) {
        alert(itemIDPPD);
        $("#design_procPlan").hide();
        $("#updDesign_procPlan").show();
    }
    else {
        $("#design_procPlan").show();
        $("#updDesign_procPlan").hide();
    }

    $("#updDesign_procPlan").on("click", function () {
        updateItem(itemIDPPD, "Procurement Plan (Design)");
    });

});

var getQueryString = function (field, url) {
    var href = url ? url : window.location.href;
    var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
    var string = reg.exec(href);
    return string ? string[1] : null;
};

function getID(pid, category) {
    var qry = "<Query><Where>" +
				     "<And>" +
         				"<Eq>" +
            				"<FieldRef Name='PlanningCategory' />" +
            				"<Value Type='Choice'>" + category + "</Value>" +
         				"</Eq>" +
         				"<Eq>" +
            				"<FieldRef Name='ProjectNumber' />" +
            				"<Value Type='Text'>" + pid + "</Value>" +
         				"</Eq>" +
      				"</And>" +
   				  "</Where>" +
   			  "</Query>";

    $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Project Projections",
        CAMLViewFields: "<ViewFields>" +
      					"<FieldRef Name='ID' />" +
      					"<FieldRef Name='PlanningCategory' />" +
      					"<FieldRef Name='ProjectNumber' />" +
   					 "</ViewFields>",
        CAMLQuery: qry,
        completefunc: function (xData, Status) {    //<-- In firefox, when I'm stepping through each line, it skips this to line 64
            //alert(xData.responseXML.xml);
            itemID = $(xData.responseXML.xml).find("z\\:row").attr("ows_ID");
            //	        alert(itemID);
        }
    });

    return itemID;
}

Open in new window

0
Isaac
Asked:
Isaac
  • 6
  • 5
1 Solution
 
leakim971PluritechnicianCommented:
You're using asynchronous ajax call which mean, itemid is not immediately availbale so you CAN'T return it at the end of your function
The following should fix it :
$(document).ready(function () {
	SP.SOD.executeOrDelayUntilScriptLoaded(retrieveData, "sp.js");
	//'SP.ClientContext',
	itemProjectNumber = getQueryString('projNumber');

	//Check to see if project number exist. If so, change buttons to update from submit
	getID(itemProjectNumber, "Procurement Plan (Design)", part2);
});

var part2 = function(itemIDPPD) {

	if (itemIDPPD) {
		alert(itemIDPPD);
		$("#design_procPlan").hide();
		$("#updDesign_procPlan").show();
	}
	else {
		$("#design_procPlan").show();
		$("#updDesign_procPlan").hide();
	}

	$("#updDesign_procPlan").on("click", function () {
		updateItem(itemIDPPD, "Procurement Plan (Design)");
	});
};

var getQueryString = function (field, url) {
	var href = url ? url : window.location.href;
	var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
	var string = reg.exec(href);
	return string ? string[1] : null;
};

function getID(pid, category, callback) {
	var qry = "<Query><Where>" +
		"<And>" +
		"<Eq>" +
		"<FieldRef Name='PlanningCategory' />" +
		"<Value Type='Choice'>" + category + "</Value>" +
		"</Eq>" +
		"<Eq>" +
		"<FieldRef Name='ProjectNumber' />" +
		"<Value Type='Text'>" + pid + "</Value>" +
		"</Eq>" +
		"</And>" +
		"</Where>" +
		"</Query>";

	$().SPServices({
		operation: "GetListItems",
		async: true,
		listName: "Project Projections",
		CAMLViewFields: "<ViewFields>" +
			"<FieldRef Name='ID' />" +
			"<FieldRef Name='PlanningCategory' />" +
			"<FieldRef Name='ProjectNumber' />" +
			"</ViewFields>",
		CAMLQuery: qry,
		completefunc: function (xData, Status) {    //<-- In firefox, when I'm stepping through each line, it skips this to line 64
			// alert(xData.responseXML.xml);
			itemID = $(xData.responseXML.xml).find("z\\:row").attr("ows_ID");
			if(typeof callback == "function") {
				callback(itemID);
			}
			// alert(itemID);
		}
	});

	//return itemID; // USELESS UNTIL YOU USE SYNCHRONOUS AJAX CALL
}

Open in new window

0
 
leakim971PluritechnicianCommented:
I see you put async: false
but modern browser disable and don't allow this as it froze the browser and it's not acceptable, human are master of the computer and should stay master of it. using async: false your computer say : "dont touch anything human, I'm working and I will give you hand on me when I will be ready for that"
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Strange.  Now it's appearing in Chrome and Firefox correctly but not IE.
Actually, the changes are not reflected in IE when I F12.  Even after I do a hard refresh, delete browser history and restart my computer, the changes are still not reflecting in IE.  very strange behavior
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
leakim971PluritechnicianCommented:
if you don't see the changes on IE, it may be related to your server, try to open the JS file directly in your IE browser
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
It finally updated but I get a new error
ie error
0
 
leakim971PluritechnicianCommented:
it's an other code.
add a dot after "document"
document.getElementsByName
and not :
documentgetElementsByName
but again, this is over the issue described here...
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Actually, the file in the server never updated.  It reverted back to the old code and not with the changes you suggested.  It did the same in Chrome and Firefox.  I am contacting the SharePoint host right now.
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Ok.  It was my fault.  I had two of the same functions in my code.
Below is an excerpt of the code and attached is my code.
    getID(itemProjectNumber, "Procurement Plan (Design)", part2);
});


var part2 = function (itemIDPPD) {
    console.log(itemIDPPD);   //<--- UNDEFINED so it causes an error in other places.
    if (itemIDPPD) {
        //alert(itemIDPPD);
        $("#design_procPlan").hide();
       

Open in new window

Please see attached file.
0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
'itemIDPPD' shows up as undefined
0
 
leakim971PluritechnicianCommented:
we're over this question.
Currently, your query return nothing so itemIDPPD is null
<rs:data ItemCount="0"></rs:data>

result of th query look like : xData.responseXML.xml
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><GetListItemsResult><listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
					<rs:data ItemCount="0">
					</rs:data>
				</listitems></GetListItemsResult></GetListItemsResponse></soap:Body></soap:Envelope>

Open in new window

0
 
IsaacSharePoint Client Side DeveloperAuthor Commented:
Thanks leakIm971!

I had to strip the code and break it down to bare minimum in jsFiddle for me to get it.  I think the problem in my call to the SharePoint list as you mentioned.

https://jsfiddle.net/isogunro/g2cr896a/
1

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now