IT Monkey:   Click Here to Help Me Build the Agenda for Upcoming Cireson Webinars!

Unsaved data and custom tasks

Matthew_DowstMatthew_Dowst Customer IT Monkey ✭
edited August 2016 in Analyst Portal

Is there a way to commit a page prior to running a task? I have implemented a custom tasks to add Manual Activity to a Service Request and Incidents. After the tasks runs it refreshed the page so that the user can now see and edit the manual activity. However, if there is unsaved data on form when the task runs the user is prompted to either stay or leave. If they choose Stay on this page, they will not loose any edits, but they will need to click Apply to have the page refresh so they can see and edit the manual activity. If they click Leave this page, it will erase all edits made, but they will be able to see the manual activity.

I've pasted the code used to create the MA below. I ran the debugger on this and saw that the strData variable is populated with the updated values, but it seems like they are ignored. I've tested this in version 6 and 5.0.9 of the portal.

function addMAtoWI (workitem, title, desc, sequenceid, type, inpa){
 //console.log("Sequence Id: " + sequenceid);
 //console.log(desc);
 var ogsr = workitem;
 var finalsr = JSON.parse(JSON.stringify(ogsr));
 var srid = ogsr.Id;
 var length = ogsr.Activity.length;
 //if there are no activities currently just add the Activity
 if (length == 0){
  finalsr.Activity.push({
      "ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",
      "SequenceId": 0,
      "Title": title,
      "Description": desc,
      "Id": "MA{0}",
      "Status": {"Id": "11fc3cef-15e5-bca4-dee0-9c1155ec8d83"}
     });
 }
 //They are adding the Activity within a Parallel Activity
 else if (inpa == true) {
  var palength = ogsr.Activity[sequenceid].Activity.length;
  //console.log (palength);
  var newseqid = palength + 1;
  //console.log (newseqid);
  //If the Parallel Activity is In Progress make the Manual Activity In Progress
  if (ogsr.Activity[sequenceid].Status.Name == "In Progress") {
     finalsr.Activity[sequenceid].Activity.push({
      "ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",
      "SequenceId": newseqid,
      "Title": title,
      "Description": desc,
      "Id": "MA{0}",
      "Status": {"Id": "11fc3cef-15e5-bca4-dee0-9c1155ec8d83"}
     });
  }
  //If the Parallel Activity is not In Progress make the Manual Activity Pending
  else {
     finalsr.Activity[sequenceid].Activity.push({
      "ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",
      "SequenceId": newseqid,
      "Title": title,
      "Description": desc,
      "Id": "MA{0}"
     });
  }  
 }
 //They are adding an Activity and it isn't within a Parallel Activity
 else if (type == "Incident"){
  var newpos = parseInt(sequenceid) + 1;
      finalsr.Activity.push({
      "ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",
      "SequenceId": newpos,
      "Title": title,
      "Description": desc,
      "Id": "MA{0}",
      "Status": {"Id": "11fc3cef-15e5-bca4-dee0-9c1155ec8d83"}
     });

   for (var i = newpos; i < length; i++) {
    finalsr.Activity[i].SequenceId = i + 1;
   }
 }
 else {
  var newpos = parseInt(sequenceid) + 1;
      finalsr.Activity.push({
      "ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",
      "SequenceId": newpos,
      "Title": title,
      "Description": desc,
      "Id": "MA{0}",
     });

   for (var i = newpos; i < length; i++) {
    finalsr.Activity[i].SequenceId = i + 1;
   }
 }
 var strData = { "formJson":{"original": ogsr, "current": finalsr}}
 //console.log (strData);
  $.ajax({
   url: "/api/V3/Projection/Commit",
   type: "POST",
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   data: JSON.stringify(strData) ,
   success: function (data2) {
    window.location.href = window.location.protocol + "//" + window.location.hostname + "/" + type + "/Edit/" + srid
   }
  });

}

Best Answer

Answers

  • Matthew_DowstMatthew_Dowst Customer IT Monkey ✭
    That worked perfectly. Thanks!
Sign In or Register to comment.