Friday, 20 May 2016

Find AIF service class name by Axd document class name

Just a quick snippet to find AIF service class name by Axd document class name.


static void GetAxdClassNameByServiceName(Args _args)
{
    #avifiles
    str                     mySearchAxdName = "AxdCountingJournal"; //Change this to your Axd class name
    List                    list;
    ListEnumerator          listEnumerator;
    SysDictClass            sysDictClass, serviceDictClass;
    AxdWizardParameters     axdWizardParameters;
    int                     progressTotal, progressCount;
    SysOperationProgress    progressBar;
   
    sysDictClass = new SysDictClass(classnum(AifDocumentService));
    list = sysDictClass.extendedBy();
   
    progressTotal = list.elements();
    progressBar   = SysOperationProgress::newGeneral(#aviUpdate, 'Axd/service class search', progressTotal);
   
    listEnumerator = list.getEnumerator();
    while (listEnumerator.moveNext())
    {
        serviceDictClass = new SysDictClass(listEnumerator.current());
       
        progressCount++;
        progressBar.incCount();
        progressBar.setText(strfmt("Searching: %1 of %2 (%3)", progressCount, progressTotal, serviceDictClass.name()));       
        progressBar.update(true);
       
        if (serviceDictClass.id() != classNum(AifGenericDocumentService))
        {
            axdWizardParameters = AifServiceClassGenerator::getServiceParameters(serviceDictClass.name());
           
            if(axdWizardParameters && axdWizardParameters.parmName() == mySearchAxdName)
            {
                info(strFmt("Aif service class name: %1", axdWizardParameters.parmAifServiceClassName()));
                info(strFmt("Document name: %1", axdWizardParameters.parmAifEntityClassName()));
                info(strFmt("Axd name: %1", axdWizardParameters.parmName()));
                info(strFmt("Query name: %1", axdWizardParameters.parmQueryName()));
               
                break;
            }
        }
    }
   
    /*
    //Use this if you know the Document class name and wanted to find the Axd class name
   
    str                     documentClassName = "LedgerGeneralJournal";
    SysDictClass            documentDictClass;
    AifDocument             documentInstance;
    AxdBase                 axdBase;
   
    documentDictClass = new SysDictClass(className2Id(documentClassName));
    documentInstance = documentDictClass.makeObject();
    axdBase = documentInstance.getAxdInstance();
   
    info(strFmt("Document name: %1", documentClassName));
    info(strFmt("Axd name: %1", classId2Name(classIdGet(axdBase))));
    info(strFmt("Query name: %1", axdBase.getQueryName()));
    */
}

No comments:

Post a Comment