Skip to content

Instantly share code, notes, and snippets.

View cgillis-aras's full-sized avatar

Chris Gillis cgillis-aras

View GitHub Profile
@cgillis-aras
cgillis-aras / labs_open_version_button.js
Created November 19, 2021 15:47
Sample code for Aras Innovator that demonstrates how to open an older version of an item using a CUI button
var generationDropdown = control.data.get("labs.part.ivcb.version_selector.dropdown");
var selectedId = generationDropdown.value;
var selItemQuery = aras.IomInnovator.newItem(options.itemTypeName, "get");
selItemQuery.setID(selectedId);
selItemQuery = selItemQuery.apply();
aras.uiShowItemEx(selItemQuery.node);
@cgillis-aras
cgillis-aras / labs_dropdown_init.js
Last active November 19, 2021 19:07
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");
@cgillis-aras
cgillis-aras / labs_newitemwithclass_execute.js
Created October 21, 2021 12:59
Sample code for Aras Innovator to open a classification dialog before opening a new item of that classification.
const itemType = options.itemType;
// Open up a classification dialog
var param = {
aras: aras,
isEditMode: true,
itemTypeName: itemType.name,
class_structure: itemType.class_structure,
dialogType: 'classification',
selectLeafOnly: true,
@cgillis-aras
cgillis-aras / labs_GetRelationshipTabIdFromItemForm.js
Created September 10, 2021 04:40
Sample code to get the title of the relationships tab
var relationshipTabInfo = parent.relationships.relTabbar;
var currentRelationshipTabId = relationshipTabInfo.GetSelectedTab();
var tabLabel = relationshipTabInfo.GetTabLabel(currentRelationshipTabId);
@cgillis-aras
cgillis-aras / labs_ParseDateFormula.cs
Created June 16, 2021 20:54
Sample code of using a Regular Expression to turn a string representation of an excel-like date formula into an actual date value.
public string EvaluateDateCalculation(string dateValue)
{
string dateFormula = @"(?:([0-9]+)[\s]*([+-])[\s]*)?(TODAY\(\))(?:[\s]*([+-])[\s]*([0-9]+))?";
System.Text.RegularExpressions.Regex dateRegex = new System.Text.RegularExpressions.Regex(dateFormula);
System.Text.RegularExpressions.Match dateMatch = dateRegex.Match(dateValue);
if (dateMatch.Success)
{
System.Text.RegularExpressions.GroupCollection calcGroups = dateMatch.Groups;
@cgillis-aras
cgillis-aras / labs_GetDateProperties.cs
Created June 16, 2021 19:53
Sample code to get all the date properties on a given ItemType.
string itemTypeName = this.getType();
Item dateProps = inn.newItem("Property", "get");
dateProps.setProperty("data_type", "date");
dateProps.setAttribute("select", "name");
Item sourceIT = dateProps.createPropertyItem("source_id", "ItemType", "get");
sourceIT.setProperty("keyed_name", itemTypeName);
sourceIT.setAttribute("select", "id");
dateProps = dateProps.apply();
@cgillis-aras
cgillis-aras / labs_CustomActionAndServerEventSupport.cs
Created June 16, 2021 18:52
Demonstrates how a single Method can be used both as a custom action and as a server event.
string actionName = this.getAction();
string thisMethodName = "labs_CalculateDynamicDate"; // Set this to the name you are using for your method
if (actionName == thisMethodName)
{
// If we get here, this is being used as a custom action, so switch to a get and return the results of that.
this.setAction("get");
return this.apply();
}
// If we get here, we are running in a server event, so just return this as normal
@cgillis-aras
cgillis-aras / labs_GenericCheckClaimedBy.cs
Created January 12, 2021 17:42
Sample code for a generic version of an action that will get the name of the User who has claimed any ItemType
Innovator inn = this.getInnovator();
// Check to see if this item is claimed at all
if (this.isLocked() == 0)
{
return inn.newResult("No one");
}
// Query to make sure that we have the locked_by_id property
string selectedType = this.getType();
@cgillis-aras
cgillis-aras / labs_HardcodedCheckClaimedBy.cs
Last active January 12, 2021 17:41
Sample code for a hard-coded version of an action that will get the name of the User who has claimed a selected Part
Innovator inn = this.getInnovator();
// Check to see if this item is claimed at all
if (this.isLocked() == 0)
{
return inn.newResult("No one");
}
// Query to make sure that we have the locked_by_id property
Item part = inn.newItem("Part", "get");
@cgillis-aras
cgillis-aras / ItemPropertyShorthands.cs
Created January 11, 2021 21:20
Examples of shorthand functions for adding items to a query in Aras Innovator.
Innovator inn = this.getInnovator();
Item part = inn.newItem("Part", "get");
// Add a Part BOM relationship to this query
Item partBom = inn.newItem("Part BOM", "get");
part.addRelationship(partBom);
// Shorthand equivalent
Item partBom = part.createRelationship("Part BOM", "get");
// Add an Item property to this query