Skip to content

Instantly share code, notes, and snippets.

@cgillis-aras
Last active November 19, 2021 19:07
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/5b3d7c920f3b3c4ab4586fa846118e9a to your computer and use it in GitHub Desktop.
Save cgillis-aras/5b3d7c920f3b3c4ab4586fa846118e9a to your computer and use it in GitHub Desktop.
Sample code for populating a CUI dropdown in Aras Innovator with a list of all of the generations of the current item
// This is to account for the case where this dropdown accidentally gets added to a non-versionable item
const isVersionableItemType = options.itemType['is_versionable'] === '1';
if (!isVersionableItemType) {
return { hidden: true };
}
/* Query for the IDs of all generations */
// Need the config ID to get all generations
// TODO: We could skip this step if we can get the config_id from the window, but it's not readily available
var configIdQuery = aras.IomInnovator.newItem(options.itemTypeName, "get");
configIdQuery.setID(options.itemId);
configIdQuery.setAttribute("select", "generation,config_id");
configIdQuery = configIdQuery.apply();
// Validate that this isn't a new item
var generationDropdown = control.data.get("labs.part.ivcb.version_selector.dropdown") || {};
var generationButton = control.data.get("labs.part.ivcb.version_selector.open_version.button") || {};
if (configIdQuery.isEmpty())
{
// This is likely a new item, so disable the functionality since it's useless unless there's multiple generations
generationDropdown.disabled = true;
generationButton.disabled = true;
return {
value: '',
options: []
};
}
else
{
// Handle the case where a new generation was created while the tab was open
generationDropdown.disabled = false;
generationButton.disabled = false;
}
var configId = configIdQuery.getProperty("config_id");
// Query for all older generations and their IDs
var allGensQuery = aras.IomInnovator.newItem(options.itemTypeName, "get");
allGensQuery.setAttribute("select", "generation,id");
allGensQuery.setAttribute("orderBy", "generation desc");
allGensQuery.setProperty("config_id", configId);
allGensQuery.setProperty("generation", "1");
allGensQuery.setPropertyAttribute("generation", "condition", "ge");
allGensQuery = allGensQuery.apply();
var allGenerations = [];
var currGenId;
for (var i = 0, numGens = allGensQuery.getItemCount(); i < numGens; i++)
{
var singleGeneration = allGensQuery.getItemByIndex(i);
var thisGenId = singleGeneration.getID();
var thisGenLabel = singleGeneration.getProperty("generation");
if (thisGenId == options.itemId)
{
// This is the current generation, so let's call it out
currGenId = thisGenId;
thisGenLabel += " (Viewing)";
}
else if (i == 0)
{
thisGenLabel += " (Current)";
}
allGenerations.push({
value: thisGenId,
label: thisGenLabel
})
}
return {
// The initial value of this item
value: currGenId,
// An array of objects containing a value and label
options: allGenerations
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment