Updating List values

Jun 23, 2011 at 10:39 AM

I'm using the spUpdateList Items and then running a workflow on the list. In the workflow, I am trying to use the Is Not Empty condition within an If statement in the workflow but the action always occurs. I have logged the value of the list item and it is showing up as "Is Not Defined". is this different than "Is Not Empty"? I've tried explictily setting the variable in my update code to Null but that did not have any effect on the value logged in the workflow history. It appears that the update is putting something into the field, but i don't know what or how. When i put an alert in my jQuery, it looks empty. Does the $(this).attr(ows_Client) statement return 'something' when the Client field is empty? if so, how can i figure out what it is or ensure that it is "empty"

I'm baffled. Does anyone have any suggestions?

TIA
Dean

Jun 23, 2011 at 3:01 PM

To check in JavaScript what a variable is represented as, you can use:

alert(typeof yourVariable);

This will return "String", "Number", "Undefined","Object".... Check here for thorough documentation: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Special/typeof

Something tells me there is something else going on with your code though.  Care to post it?  Also, what type of field is Client?

 

Cheers,

Matt

Jun 23, 2011 at 3:46 PM

Matt, below is my code. Client is a single line of text field

TIA for any assistance

Dean

function delegateActivities(){
 var startDate;
 var endDate;
 var delegator="Doe, John";
 var delegatorAccount ="parsons\54321";
 var delegate= "Doe, Jane";
 var delegateAccount = "parsons\12345";
 var ctx = SP.ClientContext.get_current();
 var items= SP.ListOperation.Selection.getSelectedItems(ctx);
 var myItems;
 var i;
 var thisID = 24;
 var strOutput=""; //processes that are delegated, used by workflow in body of email
 var count=CountDictionary(items);
 var strTitle="";
 var strActivity=null;
 var role=null;
 var responsibility=null;
 var respDescr=null;
 var client=null;
 var contractNumber=null;
 var jobNumber=null;
 var comments=null;
 var queryStringVals = new Object();
 var roleId=null;
 var delegatorTitle=null;
 var businessUnit=null;
 var sector=null;
 var outputR="";
 var outputA="";
 
 //alert ("Count "+ count);
 //alert ("item count" + items.Count);
 
 //get Id for role selected by user
  queryStringVals = $().SPServices.SPGetQueryString();
  roleId = queryStringVals['SelectedID'];
  //alert ("Role ID " + roleId);
 
// get the dates and Delegate data entered by the delegator 
 $(document).ready(function() {
  $().SPServices({
     operation: "GetListItems",
     async: false,
     listName: "DelegateAssignmentInput",
     CAMLViewFields: "<ViewFields>"+
         "<FieldRef Name='Delegate' />"+
         "<FieldRef Name='DelegateAccount' />" +
         "<FieldRef Name='EndDate' />"+
         "<FieldRef Name='Delegator'/>"+
         "<FieldRef Name='DelegatorAccount'/>"+
         "<FieldRef Name='Client'/>"+
         "<FieldRef Name='Sector'/>"+
         "<FieldRef Name='ContractNumber'/>"+
         "<FieldRef Name='JobNumber'/>"+
         "<FieldRef Name='_Comments'/>"+
         "</ViewFields>",
     completefunc: function (xData, Status) {
      //alert(xData.responseXML.xml);
        $(xData.responseXML).find("[nodeName='z:row']").each(function() {
          delegate = $(this).attr("ows_Delegate").split(";#")[1];
          //alert ("Delegate "+ delegate);
          delegateAccount=$(this).attr("ows_DelegateAccount").split(";#")[0];
          //alert ("Delegate Account" + delegateAccount);
          delegator=$(this).attr("ows_Delegator").split(";#")[1];
          //alert ("Delegator "+ delegator);
          delegatorAccount=$(this).attr("ows_DelegatorAccount").split(";#")[0];
          //alert ("Delegator Account" + delegatorAccount);
          endDate = $(this).attr("ows_EndDate");
          //alert ("ows_DndDate "+ endDate);
          startDate = $(this).attr("ows_StartDate");
          client = $(this).attr("ows_Client");
          //alert ("ows_Client "+ client);
          sector = $(this).attr("ows_Sector");
          //alert ("ows_Sector "+ sector);
          contractNumber = $(this).attr("ows_ContractNumber");
          //alert ("ows_ContractNumber "+ contractNumber);
          jobNumber = $(this).attr("ows_JobNumber");
          //alert ("ows_JobNumber "+ jobNumber);
          comments = $(this).attr("ows__Comments");
          //alert ("ows_Comments "+ comments);
    });
   }
  });
 });

// get the delegators Role  

//var roleId=1;
 $(document).ready(function() {
  $().SPServices({
     operation: "GetListItems",
     async: false,
     listName: "{8E5A81ED-A5ED-4EAE-970E-968C6DE62CF5}",
     CAMLViewFields: "<ViewFields><FieldRef Name='Role' /><FieldRef Name='Title' /><FieldRef Name='BusinessUnit'/></ViewFields>",
  CAMLQuery:"<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>"+ roleId +"</Value></Eq></Where></Query>",
     completefunc: function (xData, Status) {
      //alert(xData.responseXML.xml);
        $(xData.responseXML).find("[nodeName='z:row']").each(function() {
          role= $(this).attr("ows_Role").split(";#")[0];
          //alert ("Role "+ strRole);
          delegatorTitle=$(this).attr("ows_Title");
          //alert ("strTitle " + delegatorTitle);
          businessUnit=$(this).attr("ows_BusinessUnit").split(";#")[0];
    //alert ("business unit " + businessUnit);
    });
   }
  });
 });

 
//get the activities selected by the delegator
 for (i=0;i < count;i++)
 {
   thisID = items[i].id;
 // Get the selected items that have Required Reviews
  alert ("thisID -"+ thisID + " i =" + i + " count="+count);   
  $().SPServices({
   operation: "GetListItems",
   async: false,
   listName: "Authorities",
   CAMLViewFields:"<ViewFields><FieldRef Name='Category' /><FieldRef Name='Activity' /><FieldRef Name='Role' /><FieldRef Name='Responsibility' /></ViewFields>",
   CAMLQuery:"<Query><Where><And><Eq><FieldRef Name='Responsibility' /><Value Type='Text'>R</Value></Eq><Eq><FieldRef Name='ID' /><Value Type='Counter'>"+ thisID +"</Value></Eq></And></Where></Query>",
   completefunc: function (xData, Status){
   //alert(xData.responseXML.xml);
   //alert ("CAMLQuery" + CAMLQuery);
   // For the retreived item (you might want to grab more than one at a time)
   //create new item in Delegations list for each selected activity
    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
     strActivity= $(this).attr("ows_Activity");
     strTitle=$(this).attr("ows_Activity").split(";#")[1];
     responsibility=$(this).attr("ows_Responsibility").split(";#")[0];
     //alert ("RespAbv " + responsibility);
     respDescr=$(this).attr("ows_Responsibility").split(";#")[1];
     //alert ("RespDescr- " + respDescr);
     respTitleR = respDescr + ' - '+ strTitle; //used for email body
     alert ("respTitleR " + respTitle);
     $().SPServices({
      operation: "UpdateListItems",
      async: false,
      listName: "Delegations",
      //batch: The batch command to tell UpdateListItems what to do
      batchCmd: "New",
      valuepairs: [["Activity", strActivity],["EndDate", endDate],["StartDate",startDate], ["Delegate", delegateAccount], ["Delegator",delegatorAccount],["Responsibility",responsibility],["ItemInBatch",i+1],["TotalInBatch",count],["Client",client],["Sector",sector],["ContractNumber",contractNumber], ["JobNumber",jobNumber],["DelegatorRole",role],["DelegatorTitle",delegatorTitle],["BusinessUnit",businessUnit]],
      completefunc: function(xData, Status) {
       //alert("completed title-" + strTitle);
      }
     });
    });
   }
  });
 outputR += respTitleR+'\r';
 alert ("outputR-" + outputR);
  
 // Get the selected items that have Authority to authorize/approve/sign
  alert ("thisID -"+ thisID + " i =" + i + " count="+count);   
  $().SPServices({
   operation: "GetListItems",
   async: false,
   listName: "Authorities",
   CAMLViewFields:"<ViewFields><FieldRef Name='Category' /><FieldRef Name='Activity' /><FieldRef Name='Role' /><FieldRef Name='Responsibility' /></ViewFields>",
   CAMLQuery:"<Query><Where><And><Eq><FieldRef Name='Responsibility' /><Value Type='Text'>A</Value></Eq><Eq><FieldRef Name='ID' /><Value Type='Counter'>"+ thisID +"</Value></Eq></And></Where></Query>",
   completefunc: function (xData, Status){
   //alert(xData.responseXML.xml);
   //alert ("CAMLQuery" + CAMLQuery);
   // For the retreived item (you might want to grab more than one at a time)
   //create new item in Delegations list for each selected activity
    $(xData.responseXML).find("[nodeName='z:row']").each(function() {
     strActivity= $(this).attr("ows_Activity");
     strTitle=$(this).attr("ows_Activity").split(";#")[1];
     responsibility=$(this).attr("ows_Responsibility").split(";#")[0];
     //alert ("RespAbv " + responsibility);
     respDescr=$(this).attr("ows_Responsibility").split(";#")[1];
     //alert ("RespDescr- " + respDescr);
     respTitleA = respDescr + ' - '+ strTitle; //used for email body
     alert ("RespTitleA " + respTitle);
     $().SPServices({
      operation: "UpdateListItems",
      async: false,
      listName: "Delegations",
      //batch: The batch command to tell UpdateListItems what to do
      batchCmd: "New",
      valuepairs: [["Activity", strActivity],["EndDate", endDate],["StartDate",startDate], ["Delegate", delegateAccount], ["Delegator",delegatorAccount],["Responsibility",responsibility],["ItemInBatch",i+1],["TotalInBatch",count],["Client",client],["Sector",sector],["ContractNumber",contractNumber], ["JobNumber",jobNumber],["DelegatorRole",role],["DelegatorTitle",delegatorTitle],["BusinessUnit",businessUnit]],
      completefunc: function(xData, Status) {
       //alert("completed title-" + strTitle);
      }
     });
    });
   }
  });

 outputA += respTitleA+'\r';
 alert ("outputA-" + outputA);
// strOutput += respTitle+'\r';
 };
 
 
strOutput="Required review, prior to required approval" +'\r'+ outputR + '\r' +'Authority to authorize/approve/sign'+ '\r' + outputA;

 alert ("strOutput" + strOutput)
//get id for last item add in this batch
 var lastId=$().SPServices.SPGetLastItemId({
 listName:"Delegations"
 });
//alert("LastID " +lastId);

//alert ("Output-" + strOutput);
//var strTitle2 = 'Delegating ' + strTitle + ' '+thisID;

     $().SPServices({
      operation: "UpdateListItems",
      async: false,
      listName: "Delegations",
      ID:lastId,
      //batch: The batch command to tell UpdateListItems what to do
      batchCmd: "Update",
      valuepairs: [["AllActivitiesInBatch",strOutput]],
      completefunc: function(xData, Status) {
      // alert("body of message-" + strOutput);
      }
     });


//StartWorkflow('1/1/2011','6/1/2011','dean.gross@parsons.com','dean.gross@parsons.com','testing');
//StartWorkflow(startDate,endDate,delegate,delegate,strOutput);

};

Coordinator
Jun 25, 2011 at 4:33 PM

Dean:

Does your other thread supercede this one?

M.

Jun 27, 2011 at 2:20 PM

yes it does, sorry for causing confusion while trying to get my self less confused :)