Skip to content

Instantly share code, notes, and snippets.

@cgillis-aras
Created September 6, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cgillis-aras/f47b4fa01d89919001998ab11ce03d96 to your computer and use it in GitHub Desktop.
Save cgillis-aras/f47b4fa01d89919001998ab11ce03d96 to your computer and use it in GitHub Desktop.
Sample JavaScript code to open an item in edit mode in Aras Innovator 12.0
/*
* We need to wait for the item's form to fully load before we switch the window to edit mode.
* Luckily, aras.uiShowItem returns a Promise that happens to resolve once the window loads. This
* means we can pass in a function using Promise.then(ourFunction) that will be called after the
* Promise resolves and the item window is loaded.
*/
aras.uiShowItem("Part", "64B2100E21B44980B42FB445951310BF").then(function()
{
// Look up the tab that was just loaded
var myItemWin = aras.uiFindWindowEx("64B2100E21B44980B42FB445951310BF");
// We now want to call the same function thats called when the user clicks the Edit button on the
// item tab. Because this button is stored in CUI, we can just look up what the On Click handler
// is. In this case, the On Click handler is a JavaScript Method item called cui_ivicb_edit_click
// which simply calls this standard function below.
myItemWin.onEditCommand();
});
/*
* In my testing, I noticed some JavaScript errors when using the function above. I think this is because
* the window isn't fully loaded by the time we run onEditCommand(). These JavaScript errors didn't seem
* to impact functionality nor would they be visible to end users, but we it's still worth trying to resolve
* this problem.
*
* To do this, we'll use setTimeout() to call onEditCommand() after a set number of milliseconds. This should
* hopefully give the window more time to load which should resolve the JavaScript errors.
*/
aras.uiShowItem("Part", "64B2100E21B44980B42FB445951310BF").then(function()
{
setTimeout(function() {
var myItemWin = aras.uiFindWindowEx("64B2100E21B44980B42FB445951310BF");
myItemWin.onEditCommand();
}, 1000); // <-- You may need to tweak this value depending on the speed of your own environment.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment