Queue with Page Include doesn't warn users if unsaved changes?

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a simple Queue that loads a Page Include.  That page then has a Field Editor in Edit mode, and the page has "Warn users if page has unsaved changes" set to Yes.

If I click an item in the queue, and change the form, the proceed to click another item in the queue without saving the form, the changes are lost and there is no warning.

I tried to create a multiple action flow for Queue, where I would use a snippet to check if the model was dirty, and if so warn the user.  But I don't see a way for the snippet to abort the before running the next action nor stopping the queue from updating the page include.  I also don't see any option to Update Page Include in the multiple actions on the queue (only in the main single action dropdown).

Any ideas how to work around this?
Photo of Chris

Chris

  • 1,632 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
The "Warn Users" property really is only triggered if the page is unloaded.  In the case of this queue situation the models in the page are merely being refreshed.  Its not triggering the unsaved changes warning.  The feature is frustratingly close to what you want, but it won't work for you..  I feel your pain. 

There is an alternative, but its pretty drastic. 

Instead of using a page include to host the details you are trying to edit,  you could build all this out in one page.  Here is how. 

Step 1: Build a Detail model directly in the page with the queue.  The Detail model should only load one row and should be sorted by default so this first row is also the first item in the queue.  There should also be a condition on the record ID field.  Value should be blank (as it will be passed by an action) and it should be filterable default off. 

Step 2:  Build out the edit form you want with the field editor.

Step 3:  Go to the queue item action properties.  You can now tie an action sequence to the Queue Item Action.  The Action sequence would look something like this. 
1. Save Detail model (so we don't lose any work)
2. Activate condition and pass value:  Send the Id value from the queue to the condition in the Detail model you made above. 
3. Query model. 

By starting with save, before we change the record to the newly selected item in the queue - we won't lose any changes. 

I hope that works for you. 
Photo of Bradley Wood

Bradley Wood

  • 424 Points 250 badge 2x thumb
I used this approach and got it loading one model in the Input form okay when an item in the queue is clicked. However, I need to load 2 separate models (one read-only and one a new/editable related record) when the queue item is clicked.  For some reason it will not load both field editor components, only one or another... Any suggestions gratefully received. 
(Edited)
Photo of Chris

Chris

  • 1,632 Points 1k badge 2x thumb
Thanks, Rob.  Makes perfect sense, but I really need to use a page include if at all possible.

Is it possible (from a snippet) to change the page include based on the ID of the clicked item (to simulate the missing Update Page Include action in the multiple-actions list)? 

If so, shouldn't I be able to do the same thing from a single snippet that runs on the queue click which would locate the details page model(s) and save them, then update the page include using the ID of the clicked item?  I wouldn't have a warning (like your example would not have a warning) but at least the model would save and I would still have page includes...?

Thanks!

- Chris
Photo of Chris

Chris

  • 1,632 Points 1k badge 2x thumb
I think I got it, Rob!  Below is the snippet I have right now, which simply saves the model and then causes the page include to load the correct page.

var params = arguments[0], $ = skuid.$;
// save the model, in case there are changes waiting
skuid.model.getModelsByName().Contact.save();
// locate the Page Include and cause it to load the new contact by Id 
var includeObject = $('#Queue_Details').data('object');
includeObject.pagename = 'BDR_Contact_Details';
includeObject.querystring = '?id=' + params.row.Id;
includeObject.load();

(where #Queue_Details is the ID I put on my Page Include object)

The last thing I will play with is detecting if the model is dirty (if model.hasChanged is true), and if so popping up a message asking if the user wants to save it.  If they cancel, I can simply not change the page include and they can continue editing.

Let me know if for any reason you think this is flawed.

Thanks as always...

- Chris
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Cursory review suggests that your code should work.   The other stretegy should also work,  where a snippet is activated when a Queue Item is activated - and this snippet looks for dirty models in the included page.  I don't think you need both strategies though...