Skip to main content

There are two models, one containing a list of existing records used to populate a queue and one used in a popup to create new records. When the queue is clicked, the corresponding item is opened in a page include.

There is a Model action that requeries the “List” model whenever the “New” model is saved, that way the newly created record appears in the queue.

But how do you automatically select the newly created record so that it’s visible in the page include?

This is possible using a JavaScript snippet. After saving the “New” model, the newly created record’s Id field will be automatically updated, giving us the Id of the new record. After refreshing the “List” model, we can use a bit of javascript to search the Queue for the corresponding item, then mimic a mouse click event with jQuery. Whatever actions are associated with the queue item will then be executed.

Here’s the JavaScript:


var $ = skuid.$,<br>&nbsp; &nbsp; // Get the ID of the newly created item from the "New Item" Model. You can<br>&nbsp; &nbsp; // get this ID however is appropriate for your particular implementation.<br>&nbsp; &nbsp; newItemModel = skuid.$M( 'NewContact' ),<br>&nbsp; &nbsp; newItemId = newItemModel ? newItemModel.getFieldValue( newItemModel.getFirstRow(), 'Id' ) : false,<br>&nbsp; &nbsp; // Get the Queue containing the item to select by the Queue's UniqueID.<br>&nbsp; &nbsp; queueElm = skuid.$C('ContactsQueue'),<br>&nbsp; &nbsp; queueObj = queueElm ? queueElm.element.data('object') : false,<br>&nbsp; &nbsp; // Get the items that are currently visible in the queue. Can't do much if<br>&nbsp; &nbsp; // the item isn't visible.<br>&nbsp; &nbsp; items = queueObj ? queueObj.editor.listse0].visibleItems : i];<br>&nbsp; &nbsp;&nbsp;<br>if (!newItemId || !items) return;<br>&nbsp; &nbsp;&nbsp;<br>$.each( items, function(index,item){<br>&nbsp; &nbsp; if ( item.row.Id&nbsp;=== newItemId ){<br>&nbsp; &nbsp; &nbsp; &nbsp; // If the newly created item is found in the queue, then simulate a<br>&nbsp; &nbsp; &nbsp; &nbsp; // mouse click on it. Whatever actions you have setup (PageInclude,<br>&nbsp; &nbsp; &nbsp; &nbsp; // drawer, etc) will be executed.<br>&nbsp; &nbsp; &nbsp; &nbsp; item.element.click();<br>&nbsp; &nbsp; &nbsp; &nbsp; // Stop searching the queue...<br>&nbsp; &nbsp; &nbsp; &nbsp; return false;<br>&nbsp; &nbsp; }<br>});


Just call this snippet after refreshing the “List” model (so that the newly created record will be in the queue) but before you clear out the “New” model (so that you can still get the new record Id). Also, you need to make sure that your “List” model is sorted in such a way that newly created records will be visible when the model is re-queried. If the item isn’t visible in the Queue, then it can’t be clicked (and this snippet will just be ignored).


This works great!  Would it be possible to also scroll the queue to the selected item as well?


Reply