Merge Tools (II) - AX 2012 - Create a project from t-sql output

 Once you run the script to get the conflicting objects: http://axfaq.blogspot.ro/2014/02/merge-tool-ax-2012-another-useful.html, you can save them to .csv (the objects list), and then use the .xpo below to create a project with these objects:



 Exportfile for AOT version 1.0 or later
Formatversion: 1

***Element: CLS

; Microsoft Dynamics AX Class: IEIDECreateProjectForConflicts unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #IEIDECreateProjectForConflicts
    PROPERTIES
      Name                #IEIDECreateProjectForConflicts
      Extends             #RunBase
      Origin              #{631F2833-34E5-4A1B-9F70-69F4D2F9FCB4}
    ENDPROPERTIES
   
    METHODS
      SOURCE #classDeclaration
        #class IEIDECreateProjectForConflicts extends RunBase
        #{
        #    PrivateProjectName  projectName;
        #    FilenameOpen        fileName;
        #
        #    DialogField projectNameField;
        #    DialogField fileNameField;
        #
        #    SysProjectFilterRunBase projectFilter;
        #
        #    #define.CurrentVersion(2)
        #    #localmacro.CurrentList
        #        projectName,
        #        fileName
        #    #endmacro
        #}
      ENDSOURCE
      SOURCE #createProject
        #/// <summary>
        #///    Creates a private project.
        #/// </summary>
        #/// <param name="_projectName">
        #///    The name of the project to create.
        #/// </param>
        #protected void createProject(SharedProjectName _projectName)
        #{
        #    ProjectNode projectNode;
        #
        #    SysUpgradeProject::delete(_projectName, ProjectSharedPrivate::ProjPrivate);
        #
        #    projectNode = SysTreeNode::createProject(_projectName);
        #    projectFilter.parmProjectNode(projectNode);
        #}
      ENDSOURCE
      SOURCE #dialog
        #/// <summary>
        #/// Returns a class that contains the methods that are described by the <c>RunBaseDialogable</c>
        #/// interface.
        #/// </summary>
        #/// <returns>
        #/// A class that contains the methods that are described by the <c>RunBaseDialogable</c> interface.
        #/// </returns>
        #public Object dialog()
        #{
        #    DialogRunbase dialog = DialogRunbase::newOnClient('Create project from file', this);
        #
        #    dialog.windowType(FormWindowType::Workspace);
        #
        #    fileNameField = dialog.addField(extendedtypestr(FilenameOpen));
        #
        #    projectNameField = dialog.addField(extendedtypestr(PrivateProjectName));
        #    projectNameField.value(projectName);
        #
        #    return dialog;
        #}
      ENDSOURCE
      SOURCE #getFromDialog
        #/// <summary>
        #/// Gets the values from a dialog box.
        #/// </summary>
        #/// <returns>
        #/// true if the values can be extracted from the dialog box; otherwise, false.
        #/// </returns>
        #public boolean getFromDialog()
        #{
        #    boolean ret = super();
        #
        #    projectName = projectNameField.value();
        #    fileName = fileNameField.value();
        #
        #    return ret;
        #}
      ENDSOURCE
      SOURCE #initParmDefault
        #/// <summary>
        #/// Initializes the internal variables.
        #/// </summary>
        #/// <remarks>
        #/// This method is called when no <c>SysLastValue</c> record can be found when the program calls the
        #/// <c>SysLastValue.GetLast</c> method.Remember to call the <c>super</c> method.
        #/// </remarks>
        #public void initParmDefault()
        #{
        #    ModelRecId currentModel = xInfo::getCurrentModelId();
        #
        #    super();
        #
        #    projectName = strAlpha(SysModelStore::modelId2Name(currentModel));
        #}
      ENDSOURCE
      SOURCE #lastValueDataAreaId
        #public dataAreaId lastValueDataAreaId()
        #{
        #    return '';
        #}
      ENDSOURCE
      SOURCE #lookupModel
        #private void lookupModel(FormReferenceGroupControl _referenceGroupControl)
        #{
        #    SysModelStore::performReferenceGroupLookup(_referenceGroupControl, false);
        #
        #}
      ENDSOURCE
      SOURCE #pack
        #public container pack()
        #{
        #    return [#CurrentVersion,#CurrentList];
        #}
      ENDSOURCE
      SOURCE #parmFileName
        #public FilenameOpen parmFileName(FilenameOpen _fileName = fileName)
        #{
        #    fileName = _fileName;
        #
        #    return fileName;
        #}
      ENDSOURCE
      SOURCE #parmProjectName
        #public PrivateProjectName parmProjectName(PrivateProjectName _projectName = projectName)
        #{
        #    projectName = _projectName;
        #
        #    return projectName;
        #}
        #
      ENDSOURCE
      SOURCE #run
        #/// <summary>
        #/// Contains the code that does the actual job of the project.
        #/// </summary>
        #public void run()
        #{
        #    UtilElements            utilElements;
        #    SysModelElement         rootElement;
        #    SysModelElementType     modelElementType;
        #    str                     vsFileName = '';
        #    System.Array            textLines;
        #    int                     linesNo;
        #    int                     i, pos;
        #    SysElementName          elementName;
        #    ModelElementTypeName    elementTypeName;
        #
        #    startLengthyOperation();
        #
        #    projectFilter = new SysProjectFilterRunBase();
        #    projectFilter.grouping(SysProjectGrouping::AOT);
        #
        #    if (!System.IO.File::Exists(fileName))
        #    {
        #        info ('File not found');
        #        return;
        #    }
        #    else
        #    {
        #        textLines = System.IO.File::ReadAllLines(fileName);
        #        linesNo = textLines.GetLength(0);
        #
        #        for (i = 0; i < linesNo; i++)
        #        {
        #            vsFileName = CLRInterop::getAnyTypeForObject(textLines.GetValue(i));
        #            pos = strFind(vsFileName, ',', 0, strLen(vsFileName));
        #            elementName = subStr(vsFileName, 1, pos - 1);
        #            elementTypeName = subStr(vsFileName, pos + 1, strLen(vsFileName) - pos);
        #
        #            select rootElement
        #                where rootElement.Name == elementName &&
        #                      rootElement.ParentId == 0
        #            join modelElementType
        #                where rootElement.ElementType == modelElementType.RecId &&
        #                      modelElementType.Name == elementTypeName;
        #
        #            if (rootElement)
        #            {
        #                utilElements = null;
        #                utilElements.Name = rootElement.Name;
        #                utilElements.ParentID = rootElement.ParentId;
        #                utilElements.RecordType = rootElement.ElementType;
        #
        #                if (utilElements.RecordType == UtilElementType::SharedProject ||
        #                    utilElements.RecordType == UtilElementType::PrivateProject ||
        #                    utilElements.RecordType == UtilElementType::ClassInternalHeader ||
        #                    utilElements.RecordType == UtilElementType::TableInternalHeader ||
        #                    !projectFilter.doUtilElements(utilElements))
        #                {
        #                    info(strfmt("@SYS316339", strfmt('%1 %2', utilElements.RecordType, utilElements.Name)));
        #                }
        #            }
        #
        #            this.createProject(projectName);
        #
        #            projectFilter.write();
        #        }
        #    }
        #
        #    info ('Done.');
        #}
      ENDSOURCE
      SOURCE #unpack
        #public boolean unpack(container packedClass)
        #{
        #    Version version     = RunBase::getVersion(packedClass);
        #
        #    switch (version)
        #    {
        #        case #CurrentVersion:
        #            [version,#CurrentList] = packedClass;
        #            break;
        #        default:
        #            return false;
        #    }
        #
        #    return true;
        #}
      ENDSOURCE
      SOURCE #validate
        #public boolean validate(Object _calledFrom = null)
        #{
        #    boolean ret;
        #
        #    ret = super(_calledFrom);
        #
        #    if (!projectName)
        #    {
        #        ret = checkFailed(strfmt("@SYS50104", "@SYS6663"));
        #    }
        #    else if (!TreeNode::isValidObjectName(projectName))
        #    {
        #        ret = checkFailed(strfmt("@SYS121285", projectName));
        #    }
        #
        #    return ret;
        #}
      ENDSOURCE
      SOURCE #construct
        #public static IEIDECreateProjectForConflicts construct()
        #{
        #    return new IEIDECreateProjectForConflicts();
        #}
      ENDSOURCE
      SOURCE #main
        #public static void main(Args _args)
        #{
        #    IEIDECreateProjectForConflicts iEIDECreateProjectForConflicts = IEIDECreateProjectForConflicts::construct();
        #
        #    if (IEIDECreateProjectForConflicts.prompt())
        #    {
        #        IEIDECreateProjectForConflicts.run();
        #    }
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS

***Element: END

No comments:

Post a Comment