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_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 / ApplyAsyncWithSpinner.js
Created July 30, 2019 17:44
Showing off how to use applyAsync to display a spinner while a long query is running in Aras Innovator.
var applyWithSpinner = async function(itm) {
aras.browserHelper.toggleSpinner(document, true);
var res = await itm.applyAsync();
aras.browserHelper.toggleSpinner(document, false);
return res;
}
// Create a query we know will take a while like querying for all Methods in the system
var longQueryItem = aras.IomInnovator.newItem("Method", "get");
var res = await applyWithSpinner(longQueryItem);
@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
@cgillis-aras
cgillis-aras / RequestWithCountOnly.cs
Created December 16, 2020 20:44
An example of a method in Aras Innovator that makes a get request while using the returnMode attribute with a value of countOnly
Innovator inn = this.getInnovator();
Item newPart = inn.newItem("Part", "get");
newPart.setAttribute("returnMode", "countOnly");
newPart.setAttribute("page", "1");
newPart.setAttribute("pagesize", "10");
newPart = newPart.apply();
// The results when using returnMode="countOnly" look different than a normal item,
// so we need to retrieve them in a different way.
@cgillis-aras
cgillis-aras / RequestWithDoGetItem.cs
Created December 16, 2020 20:09
An example of a method inside of Aras Innovator that adds an item while using the doGetItem attribute
Innovator inn = this.getInnovator();
Item newPart = inn.newItem("Part", "add");
newPart.setProperty("item_number", "New Part 1");
newPart.setAttribute("doGetItem", "0");
newPart = newPart.apply();
// You can still validate the response when using doGetItem
if (newPart.isError())
{
@cgillis-aras
cgillis-aras / cui_reinit_calc_tearoff_states.js
Created November 8, 2019 14:45
Copy of the cui_reinit_calc_tearoff_states JavaScript method in Aras Innovator
var eventState = {};
var topWindow = aras.getMostTopWindowWithAras(window);
var item = topWindow.item;
var itemType = topWindow.itemType;
if (item) {
var itemTypeName = topWindow.itemTypeName;
var isTemp = aras.isTempEx(item);
var isDirty = aras.isDirtyEx(item);
var isNew = aras.isNew(item);
var lockedBy = aras.getItemProperty(item, 'locked_by_id', '');