How do I pass a var inside SPServices

May 8, 2013 at 3:13 PM
$(document).ready(function()
{

SetStatusVariable();
DisableAllSPFields();
DisableOKButton();

// query for the current user.

$().SPServices({
  operation: "GetGroupCollectionFromUser",
  userLoginName: $().SPServices.SPGetCurrentUser(),
  async: false,
  completefunc: function(xData, Status) {
// Based on if user is in group A or B certain fields are enabled.
     if($(xData.responseXML).find("Group[Name='Group A']").length == 1) 
     {
        EnableAllSPFields();
        EnableOKButton();             
     }
// I would like to evalute an (&&) based on a var set outside of the SPServices.
     if ($(xData.responseXML).find("Group[Name='Group B']").length == 1) && (status == "submit")
     {

        EnableOKButton();
        EnableSPField("Program Name");
        EnableSPField("Run Date"); 
        EnableSPField("Range Craft"); 
        EnableSPField("Range Location"); 
        EnableSPField("Range Systems");


     }

  }
});

});

Ok, my question is this viewing the code above on the second if statement I have an and condition. My issue is when I add the following code

var status =$("select[title='Form Submit Type']").val();

with in SPServices it returns a NULL via an alert I have set after the creation of the var.

alert(status);

so the && evaluation will not work.

The page is a SharePoint Edit.aspx page, thus the value I am setting is already there. I can set it outside spservices just fine
function SetStatusVariable()
{
var status =$("select[title='Form Submit Type']").val();
alert(status);
}
The problem for me is passing this value inside the second if statement to be evaluated.
     if ($(xData.responseXML).find("Group[Name='Group B']").length == 1) && (status == "submit")
Bottom line I want to evaluate if a person is in a group and if the status is equal to submit.
Coordinator
May 8, 2013 at 3:19 PM
Art:

What you're trying to do should work. I think you've got a scoping issue with your status variable. If you define it inside the function, then it won't be available outside the function.

M.
May 8, 2013 at 8:31 PM
So the issue was,

DisableAllSPFields();

Before

SP Services.

Thus, create a global var say "x" then x=SetStatusVariable();

Then

if (($(xData.responseXML).find("Group[Name='ROMS Members']").length == 1)&&(x=="Submit"))

Now it works, silly disableallspfields ugh ... haha..

Thank you Marc for the response! Also thank you for the SPServices Group Validation Code!
May 8, 2013 at 8:39 PM
I found this as a benefit,

If you disable a field, you may want to enable before submitting information!

function PreSaveAction() {
$("nobr").closest("tr").find("*").removeAttr("disabled");
return true;
}
Coordinator
May 13, 2013 at 4:12 PM