Home Analyst Portal

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.

&nbsp;&nbsp;&nbsp;for (var i = newpos; i < length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;finalsr.Activity[i].SequenceId = i + 1;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;else {<br>&nbsp;&nbsp;var newpos = parseInt(sequenceid) + 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finalsr.Activity.push({<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SequenceId": newpos,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Title": title,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Description": desc,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Id": "MA{0}",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br><br>&nbsp;&nbsp;&nbsp;for (var i = newpos; i < length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;finalsr.Activity[i].SequenceId = i + 1;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;var strData = { "formJson":{"original": ogsr, "current": finalsr}}<br>&nbsp;//console.log (strData);<br>&nbsp;&nbsp;$.ajax({<br>&nbsp;&nbsp;&nbsp;url: "/api/V3/Projection/Commit",<br>&nbsp;&nbsp;&nbsp;type: "POST",<br>&nbsp;&nbsp;&nbsp;contentType: "application/json; charset=utf-8",<br>&nbsp;&nbsp;&nbsp;dataType: "json",<br>&nbsp;&nbsp;&nbsp;data: JSON.stringify(strData) ,<br>&nbsp;&nbsp;&nbsp;success: function (data2) {<br>&nbsp;&nbsp;&nbsp;&nbsp;window.location.href = window.location.protocol + "//" + window.location.hostname + "/" + type + "/Edit/" + srid<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;});<br><br>}function addMAtoWI (workitem, title, desc, sequenceid, type, inpa){<br>&nbsp;//console.log("Sequence Id: " + sequenceid);<br>&nbsp;//console.log(desc);<br>&nbsp;var ogsr = workitem;<br>&nbsp;var finalsr = JSON.parse(JSON.stringify(ogsr));<br>&nbsp;var srid = ogsr.Id;<br>&nbsp;var length = ogsr.Activity.length;<br>&nbsp;//if there are no activities currently just add the Activity<br>&nbsp;if (length == 0){<br>&nbsp;&nbsp;finalsr.Activity.push({<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SequenceId": 0,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Title": title,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Description": desc,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Id": "MA{0}",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Status": {"Id": "11fc3cef-15e5-bca4-dee0-9c1155ec8d83"}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br>&nbsp;}<br>&nbsp;//They are adding the Activity within a Parallel Activity<br>&nbsp;else if (inpa == true) {<br>&nbsp;&nbsp;var palength = ogsr.Activity[sequenceid].Activity.length;<br>&nbsp;&nbsp;//console.log (palength);<br>&nbsp;&nbsp;var newseqid = palength + 1;<br>&nbsp;&nbsp;//console.log (newseqid);<br>&nbsp;&nbsp;//If the Parallel Activity is In Progress make the Manual Activity In Progress<br>&nbsp;&nbsp;if (ogsr.Activity[sequenceid].Status.Name == "In Progress") {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finalsr.Activity[sequenceid].Activity.push({<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SequenceId": newseqid,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Title": title,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Description": desc,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Id": "MA{0}",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Status": {"Id": "11fc3cef-15e5-bca4-dee0-9c1155ec8d83"}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;//If the Parallel Activity is not In Progress make the Manual Activity Pending<br>&nbsp;&nbsp;else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finalsr.Activity[sequenceid].Activity.push({<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SequenceId": newseqid,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Title": title,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Description": desc,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Id": "MA{0}"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br>&nbsp;&nbsp;}&nbsp;&nbsp;<br>&nbsp;}<br>&nbsp;//They are adding an Activity and it isn't within a Parallel Activity<br>&nbsp;else if (type == "Incident"){<br>&nbsp;&nbsp;var newpos = parseInt(sequenceid) + 1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finalsr.Activity.push({<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"ClassTypeId": "7ac62bd4-8fce-a150-3b40-16a39a61383d",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"SequenceId": newpos,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Title": title,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Description": desc,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Id": "MA{0}",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"Status": {"Id": "11fc3cef-15e5-bca4-dee0-9c1155ec8d83"}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br><br>

Best Answer

Answers

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