Skip to content

Instantly share code, notes, and snippets.

@cgillis-aras
Last active September 20, 2017 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgillis-aras/f09048235ec877758ae681aa4804910c to your computer and use it in GitHub Desktop.
Save cgillis-aras/f09048235ec877758ae681aa4804910c to your computer and use it in GitHub Desktop.
/*
This sample code is intended to be attached to a button through CUI.
The purpose of this code is to supplement the standard refresh functionality
with the ability to refresh an item with information from the database.
*/
var inn = this.getInnovator();
var doc = parent.frames[1].document;
if (doc)
{
// Make sure that any changes will not be overwritten unintentionally
if (top.aras.isDirtyEx(doc.thisItem.node))
{
var options = {dialogWidth: 400, dialogHeight: 200, center: true},
params = {
aras: top.aras,
message: "Refreshing from the database will overwrite your changes. Do you wish to continue?",
buttons: {
btnYes: top.aras.getResource('', 'common.yes'),
btnCancel: top.aras.getResource('', 'common.cancel')
},
defaultButton: 'btnCancel'
},
returnedValue;
var wnd = top.aras.getMainWindow();
wnd = wnd === top ? wnd.main : top;
if (wnd.showModalDialog) {
returnedValue = top.aras.modalDialogHelper.show('DefaultModal', wnd, params, options, 'groupChgsDialog.html');
} else {
returnedValue = 'btnCancel';
if (window.confirm("Refreshing from the database will overwrite your changes. Do you wish to continue?")) {
returnedValue = 'btnYes;'
}
}
if (returnedValue == 'btnCancel')
{
return null;
}
}
// Get the most recent generation of the currently opened item
var itemID = doc.itemID;
var itemType = doc.thisItem.getType();
var oldPart = inn.newItem(itemType, "get");
oldPart.setID(itemID);
oldPart = oldPart.apply();
var newPart = inn.newItem(itemType, "get");
newPart.setProperty("config_id", oldPart.getProperty("config_id"));
newPart.setProperty("is_current", "1");
newPart = newPart.apply();
// Show the newest generation of this item in the same tearoff window or tab
doc.thisItem = newPart;
top.aras.uiReShowItemEx(oldPart.getID(), doc.thisItem.node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment