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_ColorRelGridRow.js
Created May 8, 2019 15:29
Sample code to set the color of a relationship row based on property values.
// We want to style the rows of some of our relationships differently based on property value
// We're putting this in a Builder Method of a CommandBarSection so that our method is called each time the user
// clicks on a new tab.
var relationshipWeCareAbout = "159C6D88795B4A86864420863466F728"; // Put ID of relationship here
var currentRelationship = parent.relationships.currTabID;
// If we show any other relationship, don't do any additional processing
if (currentRelationship !== relationshipWeCareAbout)
{
return;
@cgillis-aras
cgillis-aras / SearchOnYesterday.cs
Last active May 3, 2019 14:07
Sample code for an onBeforeGet server event to replace the string "yesterday" in a date property with code that will search on yesterday's date.
Innovator inn = this.getInnovator();
string createdOn = this.getProperty("created_on", "");
if (createdOn == "yesterday")
{
DateTime yesterday = DateTime.Today.AddDays(-1);
DateTime eodYesterday = yesterday.AddHours(23).AddMinutes(59).AddSeconds(59);
this.setPropertyAttribute("created_on", "condition", "between");
this.setProperty("modified_on", String.Format("{0} and {1}",
yesterday.ToString("yyyy-MM-ddTHH:mm:ss"),
eodYesterday.ToString("yyyy-MM-ddTHH:mm:ss")));
@cgillis-aras
cgillis-aras / Test Open Classification.js
Last active April 24, 2019 14:15
Code to demonstrate opening the classification dialog in Aras Innovator 11.0
// Trying to open the classification dialog programmatically
var ourItemTypeName = "Part"; // <-- Change this to your ItemType name
var ourItemType = top.aras.getItemTypeForClient(ourItemTypeName, "name");
var param = {
aras: top.aras,
isEditMode: true,
itemTypeName: ourItemTypeName,
class_structure: ourItemType.getProperty("class_structure"),
dialogType: 'classification',
@cgillis-aras
cgillis-aras / labs_GetRelatedOption.js
Last active April 22, 2019 13:44
Gets the related option value from the relationship grid. This is intended to be called from an OnInsertRow event.
// Gets the related_option property from the relationships grid from an OnInsertRow event
var relOptionDropdown = this.toolbar.getItem("related_option");
// You can either perform your logic on the selected value or the selected index
/*
* Possible selected item values:
* "Create Related"
* "Pick Related"
* "No Related"
*/
@cgillis-aras
cgillis-aras / labs_SetOwnerOnInsertRow.js
Last active September 23, 2021 19:57
Sample code to update the value of a property's cell in a relationship grid.
var set_property = setRelatedItemProperty(relationshipID, "owned_by_id", "DBA5D86402BF43D5976854B8B48FCDD1");
// At this point the value is set on the item in the dom, but it does not seem to appear in the grid
// By debugging into this function, the item also does not seem to be added to the grid at this point, so we'll need to handle this logic in a timeout
setTimeout(function(relID) {
var gridApp = this.gridApplet;
var columnName = gridApp.GetPropertyColumnName("owned_by_id");
gridApp.SetCellValue(relID, gridApp.GetTrueColumnIndex(columnName), "Innovator Admin"); // <-- This should be the keyed_name of the item
}, 50, relationshipID);
@cgillis-aras
cgillis-aras / Add Part and Attach to Parent.cs
Last active March 19, 2019 20:11
Example of a custom action in Aras Innovator
Innovator inn = this.getInnovator();
Item partToAdd = this;
partToAdd.setAction("add");
string parentPartNumber = this.getAttribute("parent", "");
if (String.IsNullOrEmpty(parentPartNumber))
{
// If no parent is specified, just add the part like normal
return partToAdd.apply();
@cgillis-aras
cgillis-aras / setValueOnDelete.cs
Last active February 22, 2019 14:56
Example of setting a value of a related item in an onBeforeDelete event in Aras Innovator
Innovator inn = this.getInnovator();
// Get the relationship with the related_id
Item rel = inn.newItem(this.getType(), "get");
rel.setID(this.getID());
rel.setAttribute("select","related_id");
rel = rel.apply();
// Make the change to the related item
Item related = inn.newItem("Part", "edit");
@cgillis-aras
cgillis-aras / Open HTML File in Dialog.js
Created February 1, 2019 21:52
Sample code for displaying the content of an HTML file in a dialog within Aras Innovator
// Set the arguments being passed to the dialog
var param = {
title: "Test HTML",
aras: top.aras,
dialogWidth: 500,
dialogHeight: 250,
content: 'test.html' // Put path to HTML file here
};
// Open the dialog
@cgillis-aras
cgillis-aras / Open HTML File in New Tab.js
Created February 1, 2019 21:50
Sample code for displaying the content of an HTML file form a new tab in Aras Innovator.
// To open any window, it seems the aras object needs an item, so we're creating
// a completely blank item with a new ID that we'll use to lookup which window was just opened
var newItem = aras.IomInnovator.newItem("", "");
var newItemId = aras.generateNewGUID();
newItem.setID(newItemId);
aras.uiOpenEmptyWindowEx(newItem.node);
var newWindowName = aras.mainWindowName + "_" + newItemId;
var newWindow = aras.windowsByName[newWindowName];
@cgillis-aras
cgillis-aras / cui_printSelectedItemKeyedNames.js
Created January 16, 2019 16:03
Sample code for Aras Innovator to get the keyed_names of all selected items in the main grid.
var topWindow = aras.getMostTopWindowWithAras(window);
var workerFrame = topWindow.work;
var selectedIds = workerFrame.grid.getSelectedItemIds();
var itemTypeName = workerFrame.itemTypeName;
var selItems = aras.IomInnovator.newItem(itemTypeName, "get");
selItems.setAttribute("idlist", selectedIds.join(","));
selItems.setAttribute("select", "id,keyed_name");
selItems = selItems.apply();