1

I have a very odd problem, one that's been baffling me for over a week now. I have a workflow designed to create a new task a set period of time in the future once a current task expires. These tasks have a reminder date and a due date, a certain number of days apart.

Now, the workflow works by calculating the number of days between the due date and reminder date (which returns a negative number) and storing it in a variable (x), adding the fixed amount of time to the due date, and then adding the variable x to the new due date to get the new reminder date.

The problem in this workflow lies in how we're using it. When we run the workflow manually, the new task is generated properly and all dates match up. However, we want to run it on all items of a list, so we set the workflow to run daily using Harepoint Workflow Scheduler. When we run it using Harepoint though, strange things happen. The new due date is calculated properly, however the new reminder date has been severely miscalculated.

For example, an item with due date 8/11/2014 and reminder date 8/4/2014 (a bi-monthly task) generates a new item with due date 8/26/2014 and reminder date 9/25/2012 when run with Harepoint.

Note: I've tried a Powershell script to run the workflow on all list items to the same result. No luck.

After a bit of examination in the workflow itself, I discovered that something strange is happening when I use the "Find Interval Between Dates" workflow action to find the number of days between the due date and reminder date.

When run manually, the variable x (which holds the number of days outputted by the action) is -7 (correct). However, when run with Harepoint, the variable x is -700.

Is there some reason that running this workflow on all list items is messing with that calculation? Why is that happening? And is there anything I can do to fix this?

Any help would be appreciated. Thank you for your time.

Note: I've narrowed the problem down to that one line, which finds the number of days between due date and reminder date. When that action is executed by Harepoint or Powershell, unexpected values occur.

Note: The Powershell script produces the same problem as Harepoint, so that's not the problem.

  • Sounds like the problem may be related to HarePoint. I would allow the workflow to be run without HarePoint. – Mike Aug 11 '14 at 15:29
  • @Mike Right, it runs fine when run on an individual task item. The problem is we need it scheduled to run on all the list items daily. Something about that process is causing this error, because a PowerShell script I wrote to start the workflow on each list item produces the exact same error as HarePoint. – fuandon Aug 11 '14 at 15:42
  • Can we get your workflow code and the powershell script code? – Mike Aug 11 '14 at 17:32
  • @Mike I'm certain the powershell script is not the problem, but gimme a sec and I'll put up the relevant part of the workflow. It's a SP Designer workflow, so taking a screenshot. – fuandon Aug 11 '14 at 17:53
2

Have you considered using JQuery to do your calculations then update the list items? I have a similar thing I do with priority based off of Due Date and today's date to determaine the priority on a task. You have to convert the SharePoint Date/Time into a figure you can add and subtract easy to find how many days plus or minus you want from the value of your Date/Time Column. Take a look at this code sample and see if this is something you can use: (Used in a CEWP)

<script type="text/javascript" src="it/_layouts/js/jquery-1.8.2.js"></script>
<script type="text/javascript" src="it/_layouts/js/jquery.SPServices-0.7.2.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$().SPServices({
    operation: "GetListItems",
    listName: "IT Ticketing System",
    CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Created' /><FieldRef Name='Title' /><FieldRef Name='Priority' /></ViewFields>",

    completefunc: function (xdata, status) {
        //alert(xdata.responseXML.xml);


        $(xdata.responseXML).SPFilterNode("z:row").each(function () {


var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var hours = currentTime.getHours();
var min = currentTime.getMinutes();
var sec = currentTime.getSeconds();

if (month < 10){
month = "0" + month;
}

if (day < 10){
day = "0" + day;
}

if (sec < 10){
sec = "0" + sec;
}




var currentDate =  year+ "-" + month + "-" + day + " " + hours + ":" + min + ":" +sec;



    var xitem = $(this);

            //createdDate = xitem.attr("ows_Created").split(" ")[0];
    var createdDate = new Date(xitem.attr("ows_Created").replace(/-/g,'/'));
    var priority = xitem.attr("ows_Priority");
    var id = xitem.attr("ows_ID");

    //alert(priority);

    currentDate = new Date(currentDate.replace(/-/g,'/'));


    var timeDiff = Math.abs(createdDate - currentDate);
    var daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
    var flag = $(".flag").val();



if ((daysDiff >= "7") && (daysDiff < "14") && (priority == "(3) Low")){




$().SPServices({
      operation: "UpdateListItems",
      async: false,
      debug:true,
      listName: "IT Ticketing System",
      ID: id,
      valuepairs: [["Priority", "(2) Normal"]],
      completefunc: function (xData, Status) {

      }
    });


 }
if ((daysDiff >= "14") && (priority == "(2) Normal")){



$().SPServices({
      operation: "UpdateListItems",
      async: false,
      debug:true,
      listName: "IT Ticketing System",
      ID: id,
      valuepairs: [["Priority", "(1) High"]],
      completefunc: function (xData, Status) {

      }
    });


 }

   });
    }
 });
</script>

Now, everytime the list is visited or refreshed it runs the priority and changes an indicator I have on the list. Sound similar to what you are doing as far as Date/Time manipulation. I have found it easier to fill in the holes that the SPD workflows have with JQuery. It seems to run cleaner, and there is no need for such a heavy server request from the workflow. Makes it run a little faster too.

  • +1 for an excellent alternative. If I can't figure out why my WF is acting up I think I can make use of this, thanks! – fuandon Aug 11 '14 at 18:49
  • Great! I am glad this might be able to help you. Let me know how it turns out if you decide to use it. – lazoDev Aug 12 '14 at 13:28
0

You can add the DateJS library too, it simplifies most of the date calculations and formatting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.