Skip to content

Instantly share code, notes, and snippets.

@YMA-MDL
Created September 4, 2017 13:41
Show Gist options
  • Select an option

  • Save YMA-MDL/a58db5e01448940c002a35236e7d1bb1 to your computer and use it in GitHub Desktop.

Select an option

Save YMA-MDL/a58db5e01448940c002a35236e7d1bb1 to your computer and use it in GitHub Desktop.
SyncToolProductOnProject
Innovator inn = this.getInnovator();
if (this.getProperty("classification") == "Product") {
CCO.Utilities.WriteDebug("DEL_SyncToolProductOnProject", "Sync from Product to Tool");
// retrieve product project structure
String mainWBSid = this.getProperty("wbs_id");
Item mainWBS = inn.newItem("WBS Element", "get");
mainWBS.setID(mainWBSid);
Item submainWBS = mainWBS.createRelationship("Sub WBS", "get");
Item ToolingWBS = submainWBS.createRelatedItem("WBS Element", "get");
ToolingWBS.setProperty("name", "Tooling");
ToolingWBS.setAttribute("maxRecords", "1");
Item ToolingWBSAct = ToolingWBS.createRelationship("WBS Activity2", "get");
Item ToolingActivities = ToolingWBSAct.createRelatedItem("Activity2", "get");
mainWBS = mainWBS.apply();
Item activities = mainWBS.getItemsByXPath("//Item[@type='Activity2']");
for (int i = 0; i < activities.getItemCount(); i++) {
Item activity = activities.getItemByIndex(i);
Item toolActivity2 = inn.newItem("Activity2", "get");
toolActivity2.setAttribute("where", "[Activity2].rollupproductactivity='" + activity.getID() + "'");
toolActivity2 = toolActivity2.apply();
for (int j = 0; j < toolActivity2.getItemCount(); j++) {
// if date_due_sched is empty update date_due_sched
if (toolActivity2.getItemByIndex(j).getProperty("date_due_sched", "none") == "none") {
toolActivity2.getItemByIndex(j).setProperty("date_due_sched", activity.getProperty("date_due_sched"));
}
if (toolActivity2.getItemByIndex(j).getProperty("date_due_original", "none") == "none") {
toolActivity2.getItemByIndex(j).setProperty("date_due_original", activity.getProperty("date_due_sched"));
}
toolActivity2.getItemByIndex(j).setAction("edit");
toolActivity2.getItemByIndex(j).apply();
}
}
} else if (this.getProperty("classification") == "Tool") {
CCO.Utilities.WriteDebug("DEL_SyncToolProductOnProject", "Sync from Tool to Product");
// retrieve product project structure
String mainWBSid = this.getProperty("wbs_id");
Item mainWBS = inn.newItem("WBS Element", "get");
mainWBS.setID(mainWBSid);
Item submainWBS = mainWBS.createRelationship("Sub WBS", "get");
Item ToolingWBS = submainWBS.createRelatedItem("WBS Element", "get");
Item ToolingWBSAct = ToolingWBS.createRelationship("WBS Activity2", "get");
Item ToolingActivities = ToolingWBSAct.createRelatedItem("Activity2", "get");
mainWBS = mainWBS.apply();
Item activities = mainWBS.getItemsByXPath("//Item[@type='Activity2']");
for (int i = 0; i < activities.getItemCount(); i++) {
string rollupid = activities.getItemByIndex(i).getProperty("rollupproductactivity", "none");
if (rollupid != "none") {
Item activity = activities.getItemByIndex(i);
// find and update related activities
Item toolActivity2 = inn.newItem("Activity2", "edit");
toolActivity2.setID(activity.getID());
// get parent Item target date
Item reference = activities.getItemByIndex(i).getPropertyItem("rollupproductactivity");
reference.setAction("get");
reference = reference.apply();
if (activity.getProperty("date_due_sched", "none") == "none") {
toolActivity2.setProperty("date_due_sched", reference.getProperty("date_due_sched"));
}
if (activity.getProperty("date_due_original", "none") == "none") {
toolActivity2.setProperty("date_due_original", reference.getProperty("date_due_sched"));
}
toolActivity2 = toolActivity2.apply();
}
}
}
return this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment