Skip to content

Instantly share code, notes, and snippets.

View EliJDonahue's full-sized avatar
😃
Working on exciting new projects for the Aras Community!

Eli J. Donahue EliJDonahue

😃
Working on exciting new projects for the Aras Community!
View GitHub Profile
@EliJDonahue
EliJDonahue / aras_labs_add_text_child.cs
Created June 15, 2017 19:20
Sample code for a content generator that adds a child text element to the current element
//MethodTemplateName=CSharp:Aras.TDF.ContentGenerator(Strict);
targetElement.AddChild(this.Factory.NewText("Text", ""));
@EliJDonahue
EliJDonahue / aras_labs_custom_iteminfo_contentgenerator.cs
Created June 15, 2017 20:46
Sample code demonstrating how to customize the ItemInfo schema element content
//MethodTemplateName=CSharp:Aras.TDF.ContentGenerator(Strict);
ItemDocumentElement targetItem = targetElement as ItemDocumentElement;
if (targetItem != null) {
targetItem.ClearChilds();
targetItem.AddChild(this.Factory.NewText("Title", targetItem.GetItemProperty("name", " ")));
targetItem.AddChild(this.Factory.NewText("Text", targetItem.GetItemProperty("description", " ")));
string cost = targetItem.GetItemProperty("cost", " ");
if (cost != " ")
@EliJDonahue
EliJDonahue / aras_labs_hide_tabs.js
Created June 16, 2017 20:51
Sample code demonstrating how to hide specific relationship tabs on an Aras form
/*
This sample code hides "BOM" and "BOM Structure" tabs for OOTB Part item.
In order to make this code work for FireFox, it explicitly selects the tab
that should be loaded first -- "Alternates"
*/
var tabbar;
var desiredTabId;
//Function to hide tabs
@EliJDonahue
EliJDonahue / aras_labs_hide_tabs_bonus1.js
Created June 16, 2017 23:13
Sample code to append to aras-labs-hide-tabs.js.
// show the BOM and BOM Substitute tabs only when the Part is an assembly
if (document.thisItem.getProperty("classification","") != "Assembly")
{
//Call hideTabs function
setTimeout(hideTabs, 50);
}
@EliJDonahue
EliJDonahue / aras_labs_hide_tabs_bonus2.js
Last active June 16, 2017 23:16
Sample code to append to aras_labs_hide_tabs.js
var userIsSpecial = function(item) {
var userID = aras.getUserID();
// user is special if they are the creator
if (userID == item.getProperty("created_by_id",""))
return true;
return false;
};
if (!userIsSpecial(document.thisItem))
{
@EliJDonahue
EliJDonahue / aras_labs_access_workflow_incorrect.cs
Last active July 11, 2017 19:40
Demonstrates a sub-optimal approach to getting a Workflow item from an Activity
// 1st query
Item workflowProcess = this.newItem("Workflow Process", "get");
Item workflowProcessActivity = workflowProcess.createRelationship("Workflow Process Activity", "get");
Item activity = workflowProcessActivity.createRelatedItem("Activity", "get");
activity.setID('activityId');
workflowProcess = workflowProcess.apply();
String workflowProcessId = workflowProcess.getID();
// 2nd query
Item workflow = this.newItem("Workflow", "get");
@EliJDonahue
EliJDonahue / arasl_labs_access_workflow_best_practice.cs
Last active July 11, 2017 19:37
Demonstrates the Aras Best Practice of using the relationship structure in a single query instead of using multiple queries. This case gets a Workflow item from an Activity using one query.
// single query
Item workflow = this.newItem("Workflow","get");
Item workflowProcess = workflow.createRelatedItem("Workflow Process","get");
Item workflowProcessActivity = workflowProcess.createRelationship("Workflow Process Activity","get");
Item activity = workflowProcessActivity.createRelatedItem("Activity", "get");
activity.setID('activityId');
workflow = workflow.apply();
// generates the following AML query
// <AML>
@EliJDonahue
EliJDonahue / aras_labs_query_without_select.cs
Last active July 11, 2017 19:23
Demonstrates a sub-optimal query to retrieve the source_id and source_type properties from an Item.
Item workflow = this.newItem("Workflow","get");
Item workflowProcess = workflow.createRelatedItem("Workflow Process","get");
Item workflowProcessActivity = workflowProcess.createRelationship("Workflow Process Activity","get");
Item activity = workflowProcessActivity.createRelatedItem("Activity", "get");
activity.setID('activityId');
workflow = workflow.apply();
// generates the following AML query
// <AML>
// <Item type="Workflow" action="get">
@EliJDonahue
EliJDonahue / aras_labs_select_attribute_best_practice.cs
Last active July 11, 2017 19:23
Demonstrates the Aras Best Practice of using a select statement to retrieve only the necessary properties in a query.
Item workflow = this.newItem("Workflow","get");
// use select attribute to retrieve only the necessary properties
workflow.setAttribute("select", "source_id,source_type");
Item workflowProcess = workflow.createRelatedItem("Workflow Process","get");
Item workflowProcessActivity = workflowProcess.createRelationship("Workflow Process Activity","get");
Item activity = workflowProcessActivity.createRelatedItem("Activity", "get");
activity.setID('activityId');
workflow = workflow.apply();
// generates the following AML query
@EliJDonahue
EliJDonahue / aras_labs_select_related_name.cs
Last active July 11, 2017 19:25
Demonstrates the Aras Best Practice of using the select attribute to retrieve only the name property of the related item.