function gm_PPAT_Global_Copy_Attribute() {
var ppatAttributeCopy = function () {
ChangeAction: "_change_action"
TabItemTypeName: "gm_Work Order PPPAT",
TabName: "Pre-Prod Part Action Tab",
TopCopiedRowId: "copiedPPATRowId",
TopCopiedPropertyName: "copiedPPATPropertyName",
ExceptionForCopy: ["_current_part_number_dls", "_current_part_number_pls", "_new_part_dls", "_new_part_pls"]
var isPropertyEditable = function (currentEcrContext, row, propertyName) {
return currentEcrContext.gmPPPATChangeActionMappingNS(currentEcrContext, row, row.getProperty(constants.PropertyNames.ChangeAction, "")).getEditability(propertyName)
isPropertyEditable: isPropertyEditable
var gmArasContextUtilityNs = top[parent.thisItem.getID() + 'gmArasContextUtilityNS'];
var currentEcrContext = gmArasContextUtilityNs.getContextForId(parent.thisItem.getID());
currentEcrContext.gmGlobalAttributeCopyUtility.copy(gmArasContextUtilityNs, currentEcrContext, ppatAttributeCopy, inArgs.rowId);
return top.aras.AlertError(exception);
function gm_PPAT_Global_Paste_Attribute() {
var ppatGlobalAttributePaste = function () {
WorkOrder: "gm_Work Order",
WorkOrderPPAT: "gm_Work Order PPPAT",
PasteConfig: "gm_PPAT Paste Mapping",
PPATColorConfig: "gm_PPAT Property Config",
ChangeAction: "_change_action",
ProductLineCode: "_prod_line_cde",
DRD: "_design_division_code",
GPSArchitectureCode: "_part_fam_id_cde",
Label: "_property_label",
ConfigJson: "_config_json",
NewPartNumber: "_new_part_no",
PPAT: "Pre-Prod Part Action Tab"
PropertyCombinationValidation: {
ItemExists: "itemExists",
PastePropertyRequired: "pastePropertyRequired",
CopyPropertyRequired: "copyPropertyRequired",
PrePasteValidation: "PrePasteValidation",
PostPasteValidation: "PostPasteValidation"
var dependentPasteConstants = {
TabItemTypeName: "gm_Work Order PPPAT",
ItemId: "A945CC5D9E564CE292D8B1A67C1235FD",
TopKeyName: "PPATAttributePasteConfig",
MappingItem: "gm_PPAT Paste Mapping",
Name: "gm_PPAT Property Config",
TabName: "Pre-Prod Part Action Tab",
TopCopiedRowId: "copiedPPATRowId",
TopCopiedPropertyName: "copiedPPATPropertyName",
ExceptionForCopy: ["_current_part_number_dls", "_current_part_number_pls", "_new_part_dls", "_new_part_pls"]
var innovator = aras.newIOMInnovator();
var propertyToPaste = null;
var areConditionalPropertiesDifferent = function (propertyName, conditionalProperties) {
if (conditionalProperties) {
for (var property in conditionalProperties) {
if (property === propertyName) {
var pasteValue = pasteRow.getProperty(property, "");
var copiedValue = copiedRow.getProperty(property, "");
if (pasteValue !== copiedValue) {
var getValidConfig = function (validationConfigName) {
if (propertyToPaste.CurrentRowPasteConfig) {
var validationConfig = propertyToPaste.CurrentRowPasteConfig[validationConfigName];
if (validationConfig && (typeof (validationConfig.SourceItemType) !== "undefined" && validationConfig.SourceItemType)
&& (typeof (validationConfig.PropertyMap) !== "undefined" && validationConfig.PropertyMap)
&& (typeof (validationConfig.ValidationType) !== "undefined" && validationConfig.ValidationType)) {
var isValidCombination = function (propertyName, validationConfig) {
var pastePropertyValue = propertyToPaste.Value;
var sourcePropertyValue = propertyToPaste.Value;
var sourceItemType = validationConfig.SourceItemType;
if (typeof (validationConfig.IsItemType) !== "undefined" && validationConfig.IsItemType) {
sourcePropertyValue = propertyName === validationConfig.SourceProperty ? propertyToPaste.Value : pasteRow.getProperty(validationConfig.SourceProperty);
if (!sourcePropertyValue) {
var itemType = innovator.getItemById(sourceItemType, sourcePropertyValue);
sourcePropertyValue = itemType.getProperty(validationConfig.PropertyMap[validationConfig.SourceProperty]);
var newItemType = innovator.newItem(sourceItemType, constants.Actions.Get);
var sourceTableName = sourceItemType.replace(/ /g, '_');
for (var property in validationConfig.PropertyMap) {
var pasteRowValue = pastePropertyValue;
if (property === validationConfig.SourceProperty) {
pasteRowValue = sourcePropertyValue;
else if (propertyName !== property) {
pasteRowValue = pasteRow.getProperty(property, "");
if (pasteRowValue && pasteRowValue.trim()) {
newItemType.setProperty(validationConfig.PropertyMap[property], pasteRowValue);
var mappedProperty = validationConfig.PropertyMap[property];
whereClause += "([" + sourceTableName + "]." + mappedProperty + " is null or [" + sourceTableName + "]." + mappedProperty + " = '')";
newItemType.setAttribute(constants.Attributes.Where, whereClause);
newItemType = newItemType.apply();
if (newItemType.isError()) {
var result = newItemType.getItemByIndex(0);
if (validationConfig.ShouldUpdatePasteProperty) {
pasteRow.setProperty(validationConfig.SourceProperty, validationConfig.IsItemType ? result.getID() : result.getProperty(validationConfig.PropertyMap[propertyName]));
pasteRow.setPropertyAttribute(validationConfig.SourceProperty, constants.PropertyAttribute.KeyedName, result.getProperty(constants.PropertyAttribute.KeyedName));
var propertyNotBlank = function (currentRow, propertyName, validationConfig) {
var requiredProperties = validationConfig.RequiredProperties;
for (var i = 0; i < requiredProperties.length; i++) {
if (!currentRow.getProperty(requiredProperties[i], "")) {
var isValidPart = function (partNumber, dls, pls) {
var part = innovator.newItem(constants.ItemTypeNames.Part, constants.Actions.Get);
part.setProperty(constants.PropertyNames.PartNumber, partNumber);
whereClause += "([" + constants.ItemTypeNames.Part + "]." + constants.PropertyNames.PartDls + " is null or [" + constants.ItemTypeNames.Part + "]." + constants.PropertyNames.PartDls + " = '')";
part.setProperty(constants.PropertyNames.PartDls, dls);
part.setProperty(constants.PropertyNames.PartPls, pls);
whereClause += "([" + constants.ItemTypeNames.Part + "]." + constants.PropertyNames.PartPls + " is null or [" + constants.ItemTypeNames.Part + "]." + constants.PropertyNames.PartPls + " = '')";
part.setAttribute(constants.Attributes.Where, whereClause);
var result = part.apply();
var isValidNewDlsPls = function (propertyName, validationConfig, ecrContext) {
if (!propertyName || !validationConfig || !ecrContext) {
var newPart = ecrContext.gmUIUtilitiesNS.getPropertyKeyedName(pasteRow, constants.PropertyNames.NewPartNumber).toUpperCase();
var newDls = pasteRow.getProperty(constants.PropertyNames.NewDls, "").toUpperCase();
if (propertyName === constants.PropertyNames.NewDls) {
newDls = propertyToPaste.Value;
var changeAction = pasteRow.getProperty(constants.PropertyNames.ChangeAction, "");
isPlsValid = ecrContext.gmPPPATChangeActionMappingNS(ecrContext, pasteRow, changeAction)
.getEditability(constants.PropertyNames.NewPls);
if (ecrContext.gmPPPATChangeActionMappingNS(ecrContext, pasteRow, changeAction).getEditability(constants.PropertyNames.NewDls)) {
isDlsValid = isValidPart(newPart, newDls, null);
var previousCharcter = String.fromCharCode(newDls.charCodeAt(0) - 1);
isDlsValid = newDls.indexOf("A") >= 0 || isValidPart(newPart, previousCharcter, null);
return propertyName.toUpperCase() === constants.PropertyNames.NewDls.toUpperCase() ? isDlsValid : isPlsValid;
var isValid = function (rowToCopy, rowToPaste, pasteConfigProperty, propertyName, validationConfigName, ecrContext) {
if (!rowToCopy || !rowToPaste || !propertyName || !pasteConfigProperty) {
propertyToPaste = pasteConfigProperty;
var validationConfig = getValidConfig(validationConfigName);
if (validationConfig && areConditionalPropertiesDifferent(propertyName, validationConfig.PropertyMap)) {
switch (validationConfig.ValidationType) {
case constants.PropertyCombinationValidation.ItemExists:
return isValidCombination(propertyName, validationConfig);
case constants.PropertyCombinationValidation.PastePropertyRequired:
return propertyNotBlank(pasteRow, propertyName, validationConfig);
case constants.PropertyCombinationValidation.CopyPropertyRequired:
return propertyNotBlank(copiedRow, propertyName, validationConfig);
case constants.PropertyCombinationValidation.Numeric:
return !isNaN(copiedRow.getProperty(propertyName, "null"));
case constants.PropertyCombinationValidation.NewDlsPls:
return isValidNewDlsPls(propertyName, validationConfig, ecrContext);
var isPropertyEditable = function (currentEcrContext, row, propertyName) {
return currentEcrContext.gmPPPATChangeActionMappingNS(currentEcrContext, row, row.getProperty(constants.PropertyNames.ChangeAction, "")).getEditability(propertyName)
var exceptionPropertyToEnabledPropertyMap = function (exceptionProperty) {
switch (exceptionProperty) {
case "_current_part_number_dls":
case "_current_part_number_pls":
return "_current_part_number";
dependentPasteConstants: dependentPasteConstants,
isPropertyEditable: isPropertyEditable,
exceptionPropertyToEnabledPropertyMap: exceptionPropertyToEnabledPropertyMap
var gmArasContextUtilityNs = top[parent.thisItem.getID() + "gmArasContextUtilityNS"];
var currentEcrContext = gmArasContextUtilityNs.getContextForId(parent.thisItem.getID());
currentEcrContext.gmGlobalAttributePasteUtility.pasteAttribute(ppatGlobalAttributePaste, gmArasContextUtilityNs);
return top.aras.AlertError(exception);
function SubmitToWorkflow() {
var innovator= document.thisItem.getInnovator();
var classification= document.thisItem.getProperty("classification");
var gpsIndicator = document.thisItem.getProperty("_gps_indicator","0");
var itemId= document.thisItem.getAttribute("id");
var itemTypeID = document.thisItem.getAttribute("typeId");
var itemType = document.thisItem.getAttribute("type");
var creator= document.thisItem.getPropertyAttribute("created_by_id", "keyed_name");
var owner= document.thisItem.getPropertyAttribute("owned_by_id", "keyed_name");
var distributionList= innovator.newItem("gm_Work Order Distribution", "get");
distributionList.setProperty("source_id", itemId);
distributionList= distributionList.apply();
if(distributionList.getItemCount() <=0)
top.aras.AlertWarning("Distribution List must be populated before submitting to workflow");
var effectivePointsValidation = innovator.applyMethod("gm_PIC EffectivePointValidation", "<source_id>" + document.thisItem.getID() + "</source_id>");
if ( effectivePointsValidation.isError() === true)
top.aras.AlertError(effectivePointsValidation);
var BreakPointStockDispValidation = innovator.applyMethod("gm_EffecPt_StockDisp_Validation", "<id>" + document.thisItem.getID() + "</id>");
if ( BreakPointStockDispValidation.isError() === true)
top.aras.AlertError(BreakPointStockDispValidation);
var workflowMapId = null;
if((classification.indexOf("Work Transfer") == -1) && (classification.indexOf("Design Study") == -1) &&
(classification.indexOf("Accessory Type/AWO - NPN Request Understudy - Post MPL") == -1) && (classification.indexOf("Accessory Type/AWO - Non Impact Notify") == -1))
var validateValidationPlan = innovator.applyMethod("gm_Validation Plan Workflow Sub", "<workOrderId>" + document.thisItem.getID() + "</workOrderId>");
if ( validateValidationPlan.isError())
return top.aras.AlertError(validateValidationPlan);
var patValBody="<itemId>"+itemId+"</itemId><itemType>"+itemType+"</itemType><validateAction>submit_to_workflow</validateAction>";
var patValResult= innovator.applyMethod("gm_PATValidation", patValBody);
if(patValResult.isError())
top.aras.AlertError(patValResult);
var workflowConfig = document.thisItem.newItem("gm_WorkFlow Configuration", "get");
workflowConfig.setProperty("classification", classification);
workflowConfig = workflowConfig.apply();
for(var i=0;i< workflowConfig.getItemCount();i++)
workflowMapId = workflowConfig.getItemByIndex(i).getProperty("_workflowmap");
if(workflowMapId === null)
top.aras.AlertError("There is no workflow associated with this Type/SubType");
var workflow = innovator.newItem("Workflow", "get");
workflow.setProperty("source_id", itemId);
workflow = workflow.apply();
if (workflow.getItemCount() > 0) {
var workflowProcessId = workflow.getProperty("related_id");
var aml = encodeURI("<AML><Item type='Workflow' action='delete' where=\"[workflow].id='" + workflow.getID() + "'\"></Item></AML>");
var check = innovator.applyMethod("gm_ApplyAML with Super Perms", "<query>" + aml + "</query>");
top.aras.AlertError("Could not Instantiate Workflow : " + check.getErrorString());
var aml2 = encodeURI("<AML><Item type='Workflow Process' action='delete' where=\"[workflow_process].id='" + workflowProcessId + "'\"></Item></AML>");
var check2 = innovator.applyMethod("gm_ApplyAML with Super Perms", "<query>" + aml2 + "</query>");
top.aras.AlertError("Could not Instantiate Workflow : " + check2.getErrorString());
var body="<itemId>"+itemId+"</itemId><itemType>"+itemType+"</itemType><itemTypeID>"+itemTypeID+"</itemTypeID><workflowMapId>"+workflowMapId+"</workflowMapId>";
var result= innovator.applyMethod("GMInstantiateWorkFlow", body);
top.aras.AlertError("Could not Instantiate Workflow : " + result.getErrorString());
document.getElementById("MainDataForm")._submit_to_workflow.disabled=true;
if (document.thisItem.getProperty("_ewo_no", "") === "") {
var gpdsBody="<itemId>"+itemId+"</itemId><itemType>"+itemType+"</itemType><itemTypeID>"+itemTypeID+"</itemTypeID>";
var gpdsResult= innovator.applyMethod("gm_GenerateGpdsEwoNumber", gpdsBody);
if(gpdsResult.isError()) {
top.aras.AlertError("Could not assign GPDS EWO Number : " + gpdsResult.getErrorString());
if (gpdsResult.getItemCount() === 1) {
gmUIUtilitiesNS.setControlValue("_ewo_no", gpdsResult.getProperty("_ewo_no", ""));