Visitors

Flag Counter

Retrieve Address and contact info of a vendor

static void Sa_contactInformation(Args _args)
{
   VendTable                      vendTable;
   AccountNum                   accountNum;
   LogisticsLocation            location,location1; // need 2 buffers to get address and  contact information
   DirPartyTable                dirPartyTable1;
   LogisticsElectronicAddress   ElectronicAddres;
   DirPartyLocation             dirPartyLocation;
   LogisticsPostalAddress       PostalAddress;

 select vendTable where vendTable.AccountNum == "US_TX_003"
                                join  dirPartyTable1     where vendTable.Party          == dirPartyTable1.RecId
                                join  dirPartyLocation   where dirPartyLocation.Party   == dirPartyTable1.RecId
                                join  location           where location.RecId           == dirPartyLocation.Location
                                join  ElectronicAddres   where ElectronicAddres.Location==location.RecId
                                join  location1          where  location1.RecId         == dirPartyTable1.PrimaryAddressLocation
                                join  PostalAddress      where  PostalAddress.Location  ==location1.RecId;
 

        info(strFmt("%1 ,%2 ,%3, %4, %5",ElectronicAddres.Locator,"  ",vendTable.AccountNum,"  ",PostalAddress.Address));
     

}

Update the customer address and description

static void   Sa_address(Args _args)
{
    SysExcelApplication                 application;
    SysExcelWorkbooks                   workbooks;
    SysExcelWorkbook                    workbook;
    SysExcelWorksheets                  worksheets;
    SysExcelWorksheet                   worksheet;
    SysExcelCells                       cells;
    COMVariantType                      type1;
    int                                 row;
    CustTable                           custTable1;
    DirPartyTable                       dirPartyTable1;
    LogisticsPostalAddress              postalAddres1;
    LogisticsLocation                   location;
    FileName                            filename;
    Dialog                              dialog;
    DialogField                         dialogfield;
    AccountNum                          custAccount;
    Name                                custName;
    Description                         description,address;



    // excell data convert ionto string

     str comvariant2str(comvariant _cv, int _decimals = 0,int _characters = 0,int _separator1 = 0,int _separator2 = 0)
    {
        switch(_cv.varianttype())
        {
            case (comvarianttype::vt_bstr):
            return _cv.bstr();
            case (comvarianttype::vt_r4):
            return num2str(_cv.float(),_characters,_decimals, _separator1,_separator2);
            case (comvarianttype::vt_r8):
            return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
            case (comvarianttype::vt_decimal):
            return num2str(_cv.decimal(),_characters,_decimals, _separator1, _separator2);
            case (comvarianttype::vt_date):
            return date2str(_cv.date(),123,2,1,2, 1,4);
            case (comvarianttype::vt_empty):
            return "";
            default:
            throw error(strfmt("@sys26908",_cv.varianttype()));
        }
        return "";
     }

        // selecting the required excel file

        dialog = new dialog('Excel Import');
        dialogfield = dialog.addField(extendedTypeStr(FilenameOpen), 'File Name');
        dialog.run();
        filename =(dialogfield.value());   //file path
    try
    {
        application = SysExcelApplication::construct();
        workbooks = application.workbooks();
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }

        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1);
        cells = worksheet.cells();
        row =1;
    do
    {
        row++;
        custAccount     = cells.item(row, 1).value().bStr();
        description     = COMVariant2Str(cells.item(row, 2).value());
        address         = COMVariant2Str(cells.item(row, 3).value());


        select custTable1 where custTable1.AccountNum == custAccount
                                join  dirPartyTable1  where   custTable1.Party       == dirPartyTable1.RecId
                                join  location        where   location.RecId         == dirPartyTable1.PrimaryAddressLocation
                                join  postalAddres1   where   postalAddres1.Location == location.RecId;

        if(location.RecId)
        {
            ttsBegin;
            Location.description       = description;
            Location.selectForUpdate(true);
            Location.update();
            ttsCommit;
        }
        if(postalAddres1.RecId)
        {
            ttsBegin;
            postalAddres1.Address      = Address;
            postalAddres1.selectForUpdate(true);
            postalAddres1.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
            postalAddres1.doUpdate();
             ttsCommit;
        }


    type1 = cells.item(row+1, 1).value().variantType();

    }
      while (type1 != COMVariantType::VT_EMPTY);

      application.quit();
      info("import operation completed");


}

Importing HcmEmployee Data

static void HcmEmployeeImport(Args _args)
{

    SysExcelApplication             application;
    SysExcelWorkbooks               workbooks;
    SysExcelWorkbook                workbook;
    SysExcelWorksheets              worksheets;
    SysExcelWorksheet               worksheet;
    SysExcelCells                   cells;
    COMVariantType                  comtype;

    HcmWorker                       hcmWorker;
    HcmEmployment                   hcmEmployment;
    DirPerson                       dirPerson;
    DirPersonName                   dirPersonName;
    CompanyInfo                     companyInfo;

    HcmPersonnelNumberId            personnelNumber;
    utcDateTime                     validFrom;
    HcmEmploymentType               employmentType;
    Name                            firstName, companyName;


    int   insertcount=0;
    int row = 1;


    Dialog                          dialog;
    DialogField                     fileName;


    dialog      = new Dialog();
    dialog.caption("Select File");
    fileName    = dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.run();


    application = SysExcelApplication::construct();
    workbooks   = application.workbooks();

    try
    {
        workbooks.open(fileName.value());
    }
    catch
    {
        throw error("File cannot be opened");
    }

    workbook    = workbooks.item(1);
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1);
    cells       = worksheet.cells();

    do
    {
        row++;

        personnelNumber = cells.item(row, 2).value().bStr();
        firstName       = cells.item(row, 1).value().bStr();
        employmentType  = str2enum(employmentType, cells.item(row, 3).value().bStr());
        validFrom       = DateTimeUtil::newDateTime(cells.item(row, 4).value().date(), 0);
        companyName        = cells.item(row, 5).value().bStr();

        try
        {

            ttsbegin;
            select    hcmworker where hcmWorker.PersonnelNumber == personnelNumber;

            if(!hcmworker)
            {

                dirPerson.clear();
                dirPerson.Name          = firstName;
                dirPerson.insert();

                dirPersonName.clear();
                dirPersonName.FirstName         = firstName;
                dirPersonName.Person            = dirPerson.RecId;
                dirpersonName.insert();

                hcmWorker.clear();
                hcmWorker.Person                = dirPerson.RecId;
                hcmWorker.PersonnelNumber       = personnelNumber;
                hcmWorker.insert();

                hcmEmployment.clear();
                hcmEmployment.Worker            = hcmWorker.RecId;
                hcmEmployment.EmploymentType    = employmentType;
                hcmEmployment.ValidFrom         = validFrom;
                hcmEmployment.ValidTo           = DateTimeUtil::maxValue();
                hcmEmployment.LegalEntity       = CompanyInfo::findDataArea(companyName).RecId;
                hcmEmployment.insert();

                info(strFmt('Employee %1 created', hcmWorker.PersonnelNumber));
                insertcount++;

            }


            comtype = cells.item(row+1, 1).value().variantType();

            ttsCommit;
        }
        catch(Exception::Error)
        {
            info(strFmt("Error in row %1", row));
        }
    }
    while(comtype != COMVariantType::VT_EMPTY);

    info(strFmt("%1 Record(s) inserted", insertcount));

    application.quit();


}

Hiding the lookup elements if the element is assigned with Another records other wise lookup will shows the all elements


public void lookup()
{
 
    Query                                           query;
    QueryBuildDataSource                qbds,qbds1;
    QueryBuildRange                         qbr;
    Sa_TableA                                    sa_TableA ; // child table having form we are insering the lookup values into child table
    Sa_TableB                                    sa_TableB  ;  // this table having the lookup :parent table:
    SysTableLookup sysTableLookup =        sysTableLookup::newParameters(tableNum(sa_TableB  ), this);

    query                         = new Query();
    qbds                          = query.addDataSource(tableNum(sa_TableB  ));
    qbds1                         =qbds.addDataSource(tableNum(sa_TableA ));
    qbds1.joinMode(JoinMode::NoExistsJoin);
    qbds1.relations(true);
    //qbds1.addLink(fieldNum(sa_TableB  ,ProjectNames),fieldnum(sa_TableA ,ProjectNames));
    qbr                           = qbds.addRange(fieldNum(sa_TableB  ,ProjectNames));
    sysTableLookup.parmQuery(query);
    sysTableLookup.addLookupfield(fieldNum(sa_TableB  , ProjectNames));
    sysTableLookup.performFormLookup();
}