Job to Copy WBS (Work breakdown structure) from One Quotation to another

Recently i got chance to work on data replication tool from my period to another, where i need to create the WBS from one quotation to another quotation in some different period. i created the below job and through it is worth it to share on blog, i will keep posting some other similar job utlities that helps us in daily AX life.

static void CopyHierarchyFromOneQuotationToAnother(Args _args)
{
Hierarchy          hierarchy;
str             hierarchyId;
HierarchyTemplateCopying  hierarchyTemplateCopying;
HierarchyCreate       HierarchyCreate;
Args            args = new Args();
// Job copies the WBS (WORK BREAKDOWN STRUCTURE) from one Quotation to another.
salesQuotationTable salesQuotationTable = salesQuotationTable::find(“QA-100478”);// To Quotation
if (HierarchyLinkTable::findRefTableRecId(tablenum(SalesQuotationTable), SalesQuotationTable.RecId) == null)
{
//create Hierarchy record
hierarchyCreate = HierarchyCreate::construct(HierarchyType::Project);
hierarchyCreate.parmIsQuotation(true);
hierarchyCreate.parmSourceCommon(salesQuotationTable);
hierarchyCreate.run();
hierarchy = hierarchyCreate.parmHierarchy();
hierarchyId = hierarchy.HierarchyId;
}
else
{
hierarchyId = HierarchyLinkTable::findRefTableRecId(tablenum(SalesQuotationTable), salesQuotationTable.RecId).HierarchyId;
hierarchy = Hierarchy::find(hierarchyId);
}
hierarchyTemplateCopying = new HierarchyTemplateCopying();
hierarchyTemplateCopying.parmCopyFrom(true);
hierarchyTemplateCopying.parmHierarchy(hierarchy);
hierarchyTemplateCopying.parmShowInfolog(true);
hierarchyTemplateCopying.parmCalledFromProject(true);
hierarchyTemplateCopying.parmHierarchyTreeTable(HierarchyTreeTable::findRootLevelNode(hierarchyId));
hierarchyTemplateCopying.parmHierarchyName(“QA-100479”);// From Quotation
hierarchyTemplateCopying.run();
}