Friday 20 November 2015

class for To get the printer names lookup in ax and dialog override method and last dialog values store next time dialog opens:


To get the printer names lookup in ax and dialog override method and last dialog values store next time dialog opens:

/// <summary>
/// to show the printer name lookup
/// </summary>

class MSSpindleLabelLookup extends RunBase
{
    dialog              dialog;
    dialogGroup         dialogGroup;
    dialogField         dialogField;
    PrinterName         getPrinterName;
    container _dialogValues;
}



/// <summary>
/// to get the dialog
/// </summary>
/// <returns>
/// returns printer name what you selected
/// </returns>
/// <remarks>
/// to get the dialog
/// </remarks>
/// <exception cref="Exception::Error">
/// if user cancel the printing
/// </exception>
protected Object dialog()
{
    FormStringControl   systemprinterNames;
    ;

    dialog              = new Dialog("@MPR5759");
    dialogGroup         = dialog.addGroup("@SYS62708");
    dialogField         = dialog.addField(extendedTypeStr(PrinterName));
    systemprinterNames  = dialogField.fieldControl();
    systemprinterNames.registerOverrideMethod(methodStr(FormStringControl, lookup), MethodStr(MSSpindleLabelLookup, msprinterLookup), this);
    systemprinterNames.mandatory(true);

    //Get the previouse values
    _dialogValues = xSysLastValue::getValue(curExt(), curUserId(), UtilElementType::Job, "@SYS62708");
    //Check if we have previouse values
    if(_dialogValues != conNull())
    {
        dialogField.value(conPeek(_dialogValues, 1));
    }
    if (dialog.run())
    {
        //Save the user choices
        _dialogValues = conNull();
        _dialogValues += dialogField.value();
        xSysLastValue::putValue(_dialogValues, curExt(), curUserId(), UtilElementType::Job, "@SYS62708");

    }

    if(dialog.closedOk() == false)
        throw error("@MPR5760");
    return Dialog;
}



/// <summary>
/// get the lookup
/// </summary>
/// <param name="_formControl">
/// passing  string control
/// </param>

public  void msprinterLookup(FormStringControl _formControl )
{
    SysTableLookup                  sysTableLookup;
    TmpTableFieldLookup             tmpTableFieldLookup;
    Enumerator                      en;
    List                            entitylist      = new list(types::String);
    Map                             printerMap;
    MapEnumerator                   enumerator;
    PrinterName                     printerName;

    printerMap          = MSSpindleLabelLookup::printerMap();//If above method was created in Global class else call specific class
    enumerator          = printerMap.getEnumerator();
    while (enumerator.moveNext())
    {
        printerName = enumerator.currentValue();
        entitylist.addend(printerName);
    }

    en = entityList.getEnumerator();

    while (en.moveNext())
    {
        tmpTableFieldLookup.MSprinterName = en.current();
        tmpTableFieldLookup.insert();
    }

    sysTableLookup = SysTableLookup::newParameters(tableNum(tmpTableFieldLookup), _formControl);
    sysTableLookup.addLookupfield(fieldNum(TmpTableFieldLookup, MSprinterName));
    sysTableLookup.setLabel("@SYS62708");

    //BP Deviation documented
    sysTableLookup.parmTmpBuffer(tmpTableFieldLookup);
    sysTableLookup.performFormLookup();
}


/// <summary>
/// run the dialog
/// </summary>
/// <returns>
/// get the printer name
/// </returns>
public PrinterName runPrinterLookup()
{
    this.dialog();
    getPrinterName = dialogField.value();
    return getPrinterName;
}





public static MSSpindleLabelLookup construct()
{
    return new MSSpindleLabelLookup();
}


public static void main(Args args)
{
    MSSpindleLabelLookup  MSSpindleLabelLookup = MSSpindleLabelLookup::construct();

    MSSpindleLabelLookup.runPrinterLookup();

}



//This method loads all available printers to a Map object
static Map printerMap()
{
    Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper printerHelper;
    Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterInfo printerInfo;
    System.Collections.ArrayList names;
    System.Collections.IEnumerator enumerator;
    Map         printerMap;

    str name;
    int printerStatus;
    str driverName;
    str portName;
    str comments;
    int jobCountSinceLastReset;

    if(!printerMap)
    {
        printerMap = new Map(Types::String, Types::Container);

        // BP Deviation documented
        printerHelper = new Microsoft.Dynamics.AX.Framework.Reporting.Shared.PrinterHelper();
        names = printerHelper.get_PrinterNames();
        if (names != null)
        {
            enumerator = names.GetEnumerator();
            while (enumerator.MoveNext())
            {
                name = enumerator.get_Current();
                printerInfo = printerHelper.GetPrinterInfo(name);

                // BP Deviation documented
                printerStatus           = CLRInterop::getAnyTypeForObject(printerInfo.get_PrinterStatus());
                // BP Deviation documented
                driverName              = CLRInterop::getAnyTypeForObject(printerInfo.get_DriverName());
                // BP Deviation documented
                portName                = CLRInterop::getAnyTypeForObject(printerInfo.get_PortName());
                // BP Deviation documented
                comments                = CLRInterop::getAnyTypeForObject(printerInfo.get_Comment());
                // BP Deviation documented
                jobCountSinceLastReset  = CLRInterop::getAnyTypeForObject(printerInfo.get_JobCountSinceLastReset());

                printerMap.insert(name, [name, printerStatus, driverName, portName, comments, jobCountSinceLastReset]);
            }
        }
    }

    return printerMap;
}

Tuesday 17 November 2015

ui builder class lookup in one parameter depends on other parameters(passing range in parameters)

lookup in one parameter depends on other parameters:

here in we selected production id in parameter
that production having 4 Opr no parameter
here in i selected one opr no. parameter
for that production having 3 job identfication parameters
selected one job identification parameter
having 2 route card journal parameters

passing the range depends on above parameter we are showing lookup in other parametes





public class MSTravelCardUIBuilder extends SysOperationAutomaticUIBuilder
{
    DialogField          dialogProdId,dialogOprNum;
    DialogField          dialogProdJobId,dialogProdJournalRoute;
    MSTravelCardContract contract;
}



public void build()
{
    Dialog               dialogLocal = this.dialog();
    MSTravelCardContract contractLocal = this.dataContractObject();

    //dialogLocal.addGroup(“Parameters”);
    this.addDialogField(methodStr(MSTravelCardContract,parmProdId), contractLocal);
    this.addDialogField(methodStr(MSTravelCardContract,parmOprNum), contractLocal);
    this.addDialogField(methodStr(MSTravelCardContract,parmProdJobId), contractLocal);
    this.addDialogField(methodStr(MSTravelCardContract,parmProdJournalIdRoute), contractLocal);

}


public void getFromDialog()
{
    contract = this.dataContractObject();
    super();
}

public void initializeFields()
{
    contract = this.dataContractObject();
}

public void lookupOprNum(FormStringControl _control)
{

    Query          query = new Query();
    SysTableLookup sysTablelookup;

    sysTablelookup =SysTableLookup::newParameters(tableNum(ProdJournalRoute),_control);
    sysTablelookup.addLookupfield(fieldNum(ProdJournalRoute,OprNum));
    sysTablelookup.addLookupfield(fieldnum(ProdJournalRoute,ProdId));

    query.addDataSource(tableNum(ProdJournalRoute));
    query.dataSourceTable(tableNum(ProdJournalRoute)).addRange(fieldNum(ProdJournalRoute, ProdId)).value(queryValue(dialogProdId.value()));

    sysTablelookup.parmQuery(query);
    sysTablelookup.performFormLookup();
}



public void lookupProdJobId(FormStringControl _control)
{
    Query                   query = new Query();
    QueryBuildDataSource    qbdsJournalRoute,qbdsRouteTrans;
    SysTableLookup          sysTablelookup;

    sysTablelookup =SysTableLookup::newParameters(tableNum(ProdJournalRoute),_control);
    sysTablelookup.addLookupfield(fieldNum(ProdJournalRoute,JobId));
    sysTablelookup.addLookupfield(fieldNum(ProdJournalRoute,OprNum));
    sysTablelookup.addLookupfield(fieldnum(ProdJournalRoute,ProdId));

    qbdsJournalRoute = query.addDataSource(tableNum(ProdJournalRoute));
    qbdsJournalRoute.addRange(fieldNum(ProdJournalRoute, ProdId)).value(queryValue(dialogProdId.value()));
    qbdsJournalRoute.addRange(fieldNum(ProdJournalRoute, OprNum)).value(queryValue(dialogOprNum.value()));
    qbdsJournalRoute.addRange(fieldNum(ProdJournalRoute, QtyGood)).value(queryValue('>0'));

    qbdsRouteTrans = qbdsJournalRoute.addDataSource(tableNum(ProdRouteTrans));
    qbdsRouteTrans.addLink(fieldNum(ProdJournalRoute,ProdId),fieldNum(ProdRouteTrans,TransRefId));
    qbdsRouteTrans.addLink(fieldNum(ProdJournalRoute,JobId),fieldNum(ProdRouteTrans,JobId));
    qbdsRouteTrans.joinMode(joinmode::ExistsJoin);
    qbdsRouteTrans.addRange(fieldNum(ProdRouteTrans,TransType)).value(queryValue(ProdRouteTransType::Qty));
    qbdsRouteTrans.addRange(fieldNum(ProdRouteTrans,QtyGood)).value(queryValue('>0'));

    sysTablelookup.parmQuery(query);
    sysTablelookup.performFormLookup();

}


public void lookupProdJournalRoute(FormStringControl _control)
{

    Query                   query = new Query();
    QueryBuildDataSource    qbdsJournalRoute,qbdsRouteTrans;
    SysTableLookup sysTablelookup;

    sysTablelookup =SysTableLookup::newParameters(tableNum(ProdJournalRoute),_control);
    sysTablelookup.addLookupfield(fieldNum(ProdJournalRoute,JournalId),true);
    sysTablelookup.addLookupfield(fieldNum(ProdJournalRoute,JobId));
    sysTablelookup.addLookupfield(fieldNum(ProdJournalRoute,OprNum));
    sysTablelookup.addLookupfield(fieldnum(ProdJournalRoute,ProdId));

    qbdsJournalRoute = query.addDataSource(tableNum(ProdJournalRoute));
    qbdsJournalRoute.addRange(fieldNum(ProdJournalRoute, ProdId)).value(queryValue(dialogProdId.value()));
    qbdsJournalRoute.addRange(fieldNum(ProdJournalRoute, OprNum)).value(queryValue(dialogOprNum.value()));
    qbdsJournalRoute.addRange(fieldNum(ProdJournalRoute, QtyGood)).value(queryValue('>0'));

    qbdsRouteTrans = qbdsJournalRoute.addDataSource(tableNum(ProdRouteTrans));
    qbdsRouteTrans.addLink(fieldNum(ProdJournalRoute,ProdId),fieldNum(ProdRouteTrans,TransRefId));
    qbdsRouteTrans.addLink(fieldNum(ProdJournalRoute,JobId),fieldNum(ProdRouteTrans,JobId));
    qbdsRouteTrans.joinMode(joinmode::ExistsJoin);
    qbdsRouteTrans.addRange(fieldNum(ProdRouteTrans,TransType)).value(queryValue(ProdRouteTransType::Qty));
    qbdsRouteTrans.addRange(fieldNum(ProdRouteTrans,QtyGood)).value(queryValue('>0'));
    qbdsRouteTrans.addRange(fieldNum(ProdRouteTrans,JobId)).value(queryValue(dialogProdJobId.value()));

    sysTablelookup.parmQuery(query);
    sysTablelookup.performFormLookup();
}




public void postBuild()
{
    ;
    super();

    dialogProdId = this.bindInfo().getDialogField(
                         this.dataContractObject(),
                         methodStr(MSTravelCardContract,parmProdId));

    dialogOprNum = this.bindInfo().getDialogField(
                         this.dataContractObject(),
                         methodStr(MSTravelCardContract,parmOprNum));

    dialogOprNum.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(MSTravelCardUIBuilder, lookupOprNum), this);
    if (dialogOprNum)
    {
        dialogOprNum.lookupButton(2);
    }

    dialogProdJobId = this.bindInfo().getDialogField(
                         this.dataContractObject(),
                         methodStr(MSTravelCardContract,parmProdJobId));

    dialogProdJobId.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(MSTravelCardUIBuilder, lookupProdJobId), this);
    if (dialogProdJobId)
    {
        dialogProdJobId.lookupButton(2);
    }


    dialogProdJournalRoute = this.bindInfo().getDialogField(
                         this.dataContractObject(),
                         methodStr(MSTravelCardContract,parmProdJournalIdRoute));

    dialogProdJournalRoute.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(MSTravelCardUIBuilder, lookupProdJournalRoute), this);
    if (dialogProdJournalRoute)
    {
        dialogProdJournalRoute.lookupButton(2);
    }


}




public void postRun()
{
    super();
}


public boolean transTypeModified(FormStringControl _control)
{
    dialogProdId.value(_control.valueStr());
    dialogOprNum.value("");
    dialogProdJobId.value("");
    dialogProdJournalRoute.value("");
    return true;
}




Thursday 5 November 2015

security role

public static void main(Args _args, container _con,Noyes _printDigitopiaRouteCard)
{
    WHSWorkTable          whsWorkTable;
    MSRouteCardController MSRouteCardController = new MSRouteCardController();
    ProdTable             prodtable = _args.record();
    Args                  args = new Args();
    SecurityUserRole      securityUserRole;
    boolean  roleexist = false;
    UserId   user;

        user = curUserId();
    // added for checking the roles of current user
    while select securityUserRole where securityUserRole.User == user
    {                                                                                                 //  role name             roleid, role name            roleid
        if( (securityUserRole.SecurityRole == 886351) || (securityUserRole.SecurityRole == 886340)    //System administrator    886351, Production planner     886340
          ||(securityUserRole.SecurityRole == 886333) || (securityUserRole.SecurityRole == 886332)    //Production supervisor    886333, Production manager     886332
          ||(securityUserRole.SecurityRole == 886282) || (securityUserRole.SecurityRole == 886281) )  //Product design manager    886282, Product designer     886281
        {
            roleexist = true;
        }
    }

    select whsWorkTable
        where whsWorkTable.OrderNum   == prodtable.ProdId
        && whsWorkTable.WorkTransType == WHSWorkTransType::ProdPick
        && whsWorkTable.WorkStatus    != WHSWorkStatus::Cancelled
        && whsWorkTable.AutoExecute   == NoYes::Yes;
    if (whsWorkTable)
    {
        ttsBegin;
        MsWhsWorkAutoExecute::autoExecuteWork(whsWorkTable.WorkId);
        ttsCommit;
        if(roleexist == true && whsWorkTable.WorkId && _printDigitopiaRouteCard == NoYes::Yes)
        {
            args.record(whsWorkTable);
            MSRouteCardController::main(args,_con);
        }
    }
    else
    {
        select whsWorkTable where whsWorkTable.OrderNum      == prodtable.ProdId
                               && whsWorkTable.WorkTransType == WHSWorkTransType::ProdPick
                               && whsWorkTable.WorkStatus    != WHSWorkStatus::Cancelled;
        if(roleexist == true && whsWorkTable.WorkId && _printDigitopiaRouteCard == NoYes::Yes)
        {
            args.record(whsWorkTable);
            MSRouteCardController::main(args,_con);
        }
    }



}


Friday 23 October 2015

UI Builder class overwrite Build method for group wise parameters

if you are using UI builder class then in contract class what ever you added parameters  group by
it will not show group by for that we need to overwrite build method with this things

we need to add

DialogGroup    groupDate, groupType, groupWarehouse;


Section group by Date
    groupDate = dialog.addGroup("@SYS80056");
    groupDate.columns(1);
    groupDate.caption("@SYS80056");



Example:


/// <summary>
/// to build the parameters
/// </summary>

public void build()
{
    DialogGroup    groupDate, groupType, groupWarehouse;
    Dialog         dialogLocal = this.dialog();

    MSMasteringRejectsContract = this.dataContractObject();

    //Section group by Date
    groupDate = dialog.addGroup("@SYS80056");
    groupDate.columns(1);
    groupDate.caption("@SYS80056");
    this.addDialogField(methodStr(MSMasteringRejectsContract,parmInventJournalType), MSMasteringRejectsContract);
    this.addDialogField(methodStr(MSMasteringRejectsContract,parmmprBaseItemType), MSMasteringRejectsContract);

    //Section group by Type
    groupType = dialog.addGroup("@PSA1497");
    groupType.columns(1);
    groupType.caption("@PSA1497");
    this.addDialogField(methodStr(MSMasteringRejectsContract,parmFromDate),MSMasteringRejectsContract);
    this.addDialogField(methodStr(MSMasteringRejectsContract,parmToDate),MSMasteringRejectsContract);

    //Section group by Warehouse
    groupWarehouse = dialog.addGroup("@SYS6437");
    groupWarehouse.columns(1);
    groupWarehouse.caption("@SYS6437");
    this.addDialogField(methodStr(MSMasteringRejectsContract,parminventLocationIdOutBound),MSMasteringRejectsContract);
    this.addDialogField(methodStr(MSMasteringRejectsContract,parminventLocationIdInBound),MSMasteringRejectsContract);

}

Sunday 18 October 2015

Multi selection records in form level

when we select multiple record in form it will select 
if not selected means it will take active record 

put button property set as multiple select is yes


void clicked()
{
    MSSpindleLabelView  MSSpindleLabelViewlocal;
    MSSpindleLabelViewlocal = MSSpindleLabelView_ds.getFirst(1);
    if (MSSpindleLabelViewlocal)
    {
    while (MSSpindleLabelViewlocal.InventTransTableRecId != 0)
    {
        info(strFmt("%1 ",MSSpindleLabelViewlocal.InventTransTableRecId));
        MSSpindleLabelViewlocal = MSSpindleLabelView_ds.getNext();
    }
    }
    else
    {
        while select MSSpindleLabelViewlocal where MSSpindleLabelViewlocal.InventTransTableRecId == MSSpindleLabelView.InventTransTableRecId
        {
            info(strFmt("%1 ",MSSpindleLabelViewlocal.InventTransTableRecId));
        }
    }

    super();
}



example:


void clicked()
{
    InventTrans  InventTranslocal;
    InventTranslocal = InventTrans_ds.getFirst(1);
    if (InventTranslocal)
    {
    while (InventTranslocal.RecId != 0)
    {
        InventTrans_ds.AutoTmpCreate(true, InventTranslocal, NoYes::Yes);
        InventTranslocal = InventTrans_ds.getNext();
    }
    }
    else
    {
        while select InventTranslocal where InventTranslocal.InventTransOrigin == InventTrans.InventTransOrigin
        {
            InventTrans_ds.AutoTmpCreate(true, InventTranslocal, NoYes::Yes);
        }
        InventTransOriginMovement_ds.research(true); // for refersh the datasource
    }

    super();

}



Wednesday 7 October 2015

create financial dimension combination:

create financial dimension combination:
job:



static void FindorcreatefinancialDimesion(Args _args)
{

    DimensionAttributeValue             dimCostcenterVal,dimDepartmentVal,dimCountryVal;
    DimensionAttribute                  dimAttrCostcenter,dimAttrDepartment, dimCountry;
    DimensionAttributeValueSetStorage   davss;
    boolean                             isValidDimension = true;
    DimensionDefault   DefaultDimension;


    davss = DimensionAttributeValueSetStorage::find(DefaultDimension);
    dimAttrCostcenter           =   DimensionAttribute::findByName('CostCenter');
    dimAttrDepartment           =   DimensionAttribute::findByName('Department');
    //dimCountry              =   DimensionAttribute::findByName('Country');

    dimCostcenterVal      =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrCostcenter, "00000021", false , true);
    dimDepartmentVal      =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrDepartment, "00000042" , false, true);
    //dimCountryVal         =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimCountry, _mSSalesTable.CountryRegionCode , false, true);



    if(dimCostcenterVal )
    {
        davss.addItem(dimCostcenterVal);
    }
    if (dimDepartmentVal)
    {
        davss.addItem(dimDepartmentVal);
    }
        //davss.addItem(dimCountryVal);
    if(dimCostcenterVal || dimDepartmentVal)
       {
           DefaultDimension =   davss.save();
           //return DefaultDimension;
           info(strFmt("%1",DefaultDimension));
       }
    //else
        // return "";

    //}

}




sales table:


/// <summary>
/// Set the financial dimension based on customer details
/// </summary>
/// <param name="_mSSalesTable">
/// _mSSalesTable
/// </param>
/// <returns>
/// defaultDimension
/// </returns>
/// <remarks>
/// SO order manangement
/// </remarks>
/// <exception cref="Exception::Error">
/// exception
/// </exception>
private static DimensionDefault setFinancialDimension(MSSalesTable _mSSalesTable, SalesTable salesTable)
{
    DimensionAttributeValue             dimAttrRegionVal,dimAtrrSubProgramVal,dimCountryVal;
    DimensionAttribute                  dimAttrRegion,dimAtrrSubProgram, dimCountry;
    DimensionAttributeValueSetStorage   davss;
    boolean                             isValidDimension = true;


    davss = DimensionAttributeValueSetStorage::find(salesTable.DefaultDimension);
    dimAttrRegion           =   DimensionAttribute::findByName('Region');
    dimAtrrSubProgram       =   DimensionAttribute::findByName('SubProgram');
    dimCountry              =   DimensionAttribute::findByName('Country');

    dimAttrRegionVal      =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrRegion, _mSSalesTable.Region, false , true);
    dimAtrrSubProgramVal  =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAtrrSubProgram, _mSSalesTable.SubRegion , false, true);
    dimCountryVal         =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimCountry, _mSSalesTable.CountryRegionCode , false, true);

    if (!dimAttrRegionVal)
    {
        isValidDimension = false;
        _mSSalesTable.Comments = strFmt("@MPR4954", _mSSalesTable.Region);
    }
    if (!dimAtrrSubProgramVal)
    {
        isValidDimension = false;
        _mSSalesTable.Comments =  _mSSalesTable.Comments + '\n' + strFmt("@MPR4955", _mSSalesTable.SubRegion);
    }

    if (!dimCountryVal)
    {
        isValidDimension = false;
        _mSSalesTable.Comments =  _mSSalesTable.Comments + '\n' + strFmt("@MPR4956", _mSSalesTable.CountryRegionCode);
    }
    if (!isValidDimension)
    {
        ttsBegin;
        _mSSalesTable.selectForUpdate(true);
        _mSSalesTable.update();
        ttsCommit;
        throw error("@MPR4959");
    }


    if(dimAttrRegionVal && dimAtrrSubProgramVal && dimCountryVal )
    {
        davss.addItem(dimAttrRegionVal);
        davss.addItem(dimAtrrSubProgramVal);
        davss.addItem(dimCountryVal);

        return  davss.save();
    }

    return 0;
}


my code in class:

/// <summary>
/// for getting dimension id 
/// </summary>
/// <param name="_dataRecord">
/// 2009 data record
/// </param>
/// <returns>
/// returns financial dimension
/// </returns>
/// <remarks>
/// added by v-irsha for get dimension id
/// </remarks>

public DimensionDefault findDefaultDimId(AxeDataRecord _dataRecord)
{

    DimensionAttributeValue             dimCostcenterVal,dimDepartmentVal;
    DimensionAttribute                  dimAttrCostcenter,dimAttrDepartment;
    DimensionAttributeValueSetStorage   davss;
    boolean                             isValidDimension = true;
    DimensionDefault                    DefaultDimension;


    davss = DimensionAttributeValueSetStorage::find(DefaultDimension);
    dimAttrCostcenter           =   DimensionAttribute::findByName('CostCenter');
    dimAttrDepartment           =   DimensionAttribute::findByName('Department');

    dimCostcenterVal      =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrCostcenter, _dataRecord.value('Dimension2_'), false , true);
    dimDepartmentVal      =   DimensionAttributeValue::findByDimensionAttributeAndValueNoError(dimAttrDepartment, _dataRecord.value('Dimension') , false, true);



    if(dimCostcenterVal )
    {
        davss.addItem(dimCostcenterVal);
    }
    if (dimDepartmentVal)
    {
        davss.addItem(dimDepartmentVal);
    }
    
    if(dimCostcenterVal || dimDepartmentVal)
    {
        DefaultDimension =   davss.save();
        return DefaultDimension;
    }
    else
        return 0;

}








Tuesday 6 October 2015

Need to refresh the datasource from one form to another form:

Need to refresh the datasource from one form to another form:


We need to refresh the data from one form to another form

FormB is opening from formA if I did any changes in formB and close that formB then what ever the field exist in formB is same exist in FormA after changing without I clicked refresh(F5) in formA it needs to get refresh
So I write like below


I written formB close method as like

void close()
{
    FormDataSource   msProdCaller;
    ;
   
    super();

    if (element.args().caller().name() == formStr(FormA))
    {

        msProdCaller = element.args().record().dataSource();
        if (msProdCaller)
        msProdCaller.research();

    }


}

Wednesday 16 September 2015

address import(zipcode,city,state,county,country/ region id) insert through excel sheet

static void AddressImport(Args _args)
{
    SysExcelApplication             application;
    SysExcelWorkbooks               workbooks;
    SysExcelWorkbook                workbook;
    SysExcelWorksheets              worksheets;
    SysExcelWorksheet               worksheet;
    SysExcelCells                   cells;
    COMVariantType                  type;
    Name                            name;
    FileName                        filename;
    InventPosting                   InventPosting;

    DimensionAttributeValueCombination DimensionAttributeValueCombination;

    int row =1;
    LogisticsAddressZipCode          zipCode;
    LogisticsAddressZipCodeId        zipCodeId;
    LogisticsAddressCity             city;
    LogisticsAddressStateId          stateId;
    LogisticsAddressState            state;
    LogisticsAddresssCity            cityRecord;
    LogisticsAddressCountyName       countyName;
    LogisticsAddressCountyId         countyId;
    LogisticsAddressCounty           county;

    boolean                          badRecord;
    int                              i=1;
    int                              numProcessedRecords=0;
    LogisticsAddressCountryRegionId  _countryRegionId;

    //LogisticsAddressStateId          stateId;
    //LogisticsAddressCountyId         countyId;
    //LogisticsAddressCountyName       countyName;

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

    //specify the file path that you want to read
    filename    = "C:\\Users\\v-irsha\\Desktop\\2009 DMF\\Vendor\\Vend addresses countycountryregidstatecityzipcode WITH NO EMPTY ROWSCOLUMN.xlsx";
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }

    ttsbegin;
    workbook    = workbooks.item(1);
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1); //Here 3 is the worksheet Number
    cells       = worksheet.cells();

    do
    {
        row++;
        zipCodeId        = cells.item(row, 2).value().bStr();
        if (zipCodeId == "")
            zipCodeId = int2str(cells.item(row, 2).value().double());

        stateId          = cells.item(row, 3).value().bStr();
        city             = cells.item(row, 5).value().bStr();
        _countryRegionId = cells.item(row, 1).value().bStr();
       /// switch(_countryRegionId )
        //{
            //case "US" :
            //_countryRegionId = _countryRegionId +"A";
            //break;
            //case "Brazil" :
             //_countryRegionId = "BRA";
            //break;
            //case "Mexico" :
             //_countryRegionId = "MEX";
            //break;
            //case "Colombia" :
             //_countryRegionId = "COL";
            //break;
            //case "Argentina" :
             //_countryRegionId = "ARG";
            //break;
            //case "Japan" :
             //_countryRegionId = "JPN";
            //break;
            //case "Canada" :
             //_countryRegionId = "CAN";
            //break;
            //case "CA" :
             //_countryRegionId = "CAN";
            //break;
            //case "COSTA RICA" :
             //_countryRegionId = "CRI";
            //break;
            //
        //}
        countyId         = cells.item(row, 4).value().bStr();

        if (stateId != '')
            state= LogisticsAddressState::find(_countryRegionId, stateId);
            if (!state.RecId)
            {
                state.CountryRegionId   = _countryRegionId;
                state.StateId           = stateId;
                state.insert();
            }
            // Check if county exists
            if(countyId != '')
            county = LogisticsAddressCounty::find(_countryRegionId, stateId, countyId);
                if(!county.RecId)
        {
            county.CountyId = countyId;
            county.Name = countyId;
            county.CountryRegionId = _countryRegionId;
            county.StateId = stateId;
            county.insert();
        }
            if (city != '')
            {
                select firstonly cityRecord where
                    cityRecord.Name             == city &&
                    cityRecord.StateId          == stateId &&
                    cityRecord.CountryRegionId  == _countryRegionId &&
                    cityRecord.CountyId         == countyId;
            }

            if (!cityRecord.RecId)
            {
                cityRecord.CountryRegionId  = _countryRegionId;
                cityRecord.Name             = city;
                cityRecord.StateId          = stateId;
                cityRecord.CountyId         = countyId;
                cityRecord.insert();
            }

            select firstonly zipCode where
                zipCode.ZipCode         == zipCodeId &&
                zipCode.State           == stateId &&
                zipCode.County          == countyId &&
                zipCode.CountryRegionId == _countryRegionId &&
                zipCode.CityRecId       == cityRecord.RecId;

            if (!zipCode.RecId)
            {
                zipCode.ZipCode         = zipCodeId;
                zipCode.City            = city;
                zipCode.CityRecId       = cityRecord.RecId;
                zipCode.CountryRegionId = _countryRegionId;
                zipCode.State           = stateId;
                zipCode.County          = countyId;
                zipCode.insert();

                numProcessedRecords++;
            }

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

    while (type != COMVariantType::VT_EMPTY);

    info(strFmt("%1 Inserted",numProcessedRecords));

    ttsCommit;

    application.quit();
}





new job with streeet also:


static void ImportAddress(Args _args)
{
    SysExcelApplication                 application;
    SysExcelWorkbooks                   workbooks;
    SysExcelWorkbook                    workbook;
    SysExcelWorksheets                  worksheets;
    SysExcelWorksheet                   worksheet;
    SysExcelCells                       cells;
    COMVariantType                      type;
    Name                                name;
    FileName                            filename;

    DimensionAttributeValueCombination  DimensionAttributeValueCombination;

    int row = 1;
    LogisticsAddressZipCode             zipCode;
    LogisticsAddressZipCodeId           zipCodeId;
    LogisticsAddressCity                city;
    LogisticsAddressStateId             stateId;
    LogisticsAddressState               state;
    LogisticsAddresssCity               cityRecord;
    LogisticsAddressCountyName          countyName;
    LogisticsAddressCountyId            countyId;
    LogisticsAddressCounty              county;
    LogisticsAddressStreet_RU           Street;
    Description                         Street_name,Street_id;
    LogisticsPostalAddress              PostalAddress;
    LogisticsAddressing                 Address;
    EffectiveDateTime                   validFrom;
    ExpirationDateTime                  validTo;

    boolean                             badRecord;
    int                                 i = 1;
    int                                 numProcessedRecords = 0;
    LogisticsAddressCountryRegionId     _countryRegionId;

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

    //specify the file path that you want to read
    //filename    = "C:\\DMF\\DIXF_vimsin\\Ready to Import\\Imported on 26102015\\AddressMasterDIT01_26102015.xlsx";
    filename    = "C:\\Users\\v-irsha\\Desktop\\28 oct 2015 cust\\AX2009 Customer addresses master.xlsx";//"C:\\DMF\\DIXF_vimsin\\Ready to Import\\Imported on 26102015\\AX2009 Customer addresses master.xlsx";
    //filename    = "C:\\Users\\v-vimsin\\Documents\\Vimal\\DIXF\\LogisticsPostalAddress - Copy.xlsx";
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }

    ttsbegin;
    workbook    = workbooks.item(1);
    worksheets  = workbook.worksheets();
    worksheet   = worksheets.itemFromNum(1); //Here 1 is the worksheet Number
    cells       = worksheet.cells();

    do
    {
        row++;
        zipCodeId        = cells.item(row, 4).value().bStr();
        if (zipCodeId == "")
            zipCodeId = int2str(cells.item(row, 4).value().double());

        stateId             = cells.item(row, 3).value().bStr();
        city                = cells.item(row, 2).value().bStr();
        _countryRegionId    = cells.item(row, 1).value().bStr();
        countyId            = cells.item(row, 5).value().bStr();
        Street_name         = cells.item(row, 6).value().bStr();
        Address             = cells.item(row, 7).value().bStr();
        validFrom           = str2datetime(cells.item(row, 8).value().bStr(),213);
        validTo             = str2datetime(cells.item(row, 9).value().bStr(),213);

        if (stateId != "")
        {
            state= LogisticsAddressState::find(_countryRegionId, stateId);
            if (!state.RecId)
            {
                state.CountryRegionId   = _countryRegionId;
                state.StateId           = stateId;
                state.insert();
            }
        }
            // Check if county exists
        if (countyId != "")
        {
            county = LogisticsAddressCounty::find(_countryRegionId, stateId, countyId);
            if (!county.RecId)
            {
                // County needs a state
                county.CountryRegionId  = _countryRegionId;
                county.StateId          = stateId;
                county.CountyId         = countyId;
                county.Name             = countyName;
                county.insert();
            }
        }
         // Check if city exists
        if (city != '')
        {
            select firstonly cityRecord where
                cityRecord.Name             == city &&
                cityRecord.StateId          == stateId &&
                cityRecord.CountryRegionId  == _countryRegionId &&
                cityRecord.CountyId         == countyId;

            if (!cityRecord.RecId)
            {
                cityRecord.CountryRegionId  = _countryRegionId;
                cityRecord.Name             = city;
                cityRecord.StateId          = stateId;
                cityRecord.CountyId         = countyId;
                cityRecord.insert();
            }
        }
        // Check if Street exists
        if (Street_name != "")
        {
            Street = LogisticsAddressStreet_RU::find(Street_name, _countryRegionId,stateId,countyId,LogisticsAddresssCity::find(city).RecId,0);
            if (!Street.RecId)
            {
                Street.CountryRegion    = _countryRegionId;
                Street.City             = LogisticsAddresssCity::find(city).RecId;
                Street.State            = stateId;
                Street.County           = countyId;
                Street.Name             = Street_name;
                Street.Description      = Street_name;
                Street.insert();
            }
        }
        // Check if zipCode exists
        if (zipCodeId != "")
        {
            select firstonly zipCode where
                zipCode.ZipCode         == zipCodeId &&
                zipCode.State           == stateId &&
                zipCode.County          == countyId &&
                zipCode.CountryRegionId == _countryRegionId &&
                zipCode.CityRecId       == cityRecord.RecId;

            if (!zipCode.RecId)
            {
                zipCode.ZipCode         = zipCodeId;
                zipCode.City            = city;
                zipCode.CityRecId       = cityRecord.RecId;
                zipCode.CountryRegionId = _countryRegionId;
                zipCode.State           = stateId;
                zipCode.County          = countyId;
                zipCode.StreetName      = Street_name;
                zipCode.insert();

                numProcessedRecords++;
            }
        }
        // insert address into table LogisticsPostalAddress
        /*if (Address != "")
        {
            select firstOnly PostalAddress
                where PostalAddress.CityRecId == cityRecord.RecId
                   && PostalAddress.CountryRegionId == _countryRegionId
                   && PostalAddress.State == state.StateId
                   && PostalAddress.StreetId_RU == Street.RecId
                   && PostalAddress.ZipCodeRecId == zipCode.RecId;
            if (!PostalAddress.RecId)
            {
                PostalAddress.Address           = Address;
                PostalAddress.ValidFrom         = validFrom;
                PostalAddress.ValidTo           = validTo;
                PostalAddress.CityRecId         = cityRecord.RecId;
                PostalAddress.City              = cityRecord.Name;
                PostalAddress.CountryRegionId   = _countryRegionId;
                PostalAddress.State             = state.StateId;
                PostalAddress.County            = county.CountyId;
                PostalAddress.StreetId_RU       = Street.RecId;
                PostalAddress.Street            = Street.Name;
                PostalAddress.ZipCodeRecId      = zipCode.RecId;
                PostalAddress.ZipCode           = zipCode.ZipCode;
                PostalAddress.insert();
            }
        }*/

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

    while (type != COMVariantType::VT_EMPTY);

    info(strFmt("%1 Inserted",numProcessedRecords));

    ttsCommit;

    application.quit();
}







Wednesday 12 August 2015

Inserting new dim id in inventdim table



public inventDimId findorCreateInventdimId(InventBatchId _batchNo, InventSerialId _reelNo,ItemId _ItemId,InventdimId _InventdimId)
{
    InventSerial InventSerial;
    InventBatch  InventBatch;
    InventDim    InventDimselect,InventDimLoc;
    ;

    InventDimselect = InventDim::find(_InventdimId);
    ttsBegin;
    select /*itemId,InventBatchId from*/ forupdate InventBatch where InventBatch.itemId        == _ItemId
                                                    && InventBatch.inventBatchId == _batchNo;
    if(!InventBatch)
    {
        InventBatch.itemId        = _ItemId;
        InventBatch.inventBatchId = _batchNo;
        InventBatch.insert();
    }
    ttsCommit;
    ttsBegin;
    select /*InventSerialId,ItemId from*/ forupdate InventSerial where InventSerial.InventSerialId == _reelNo
                                                      && InventSerial.ItemId         == _ItemId;
    if(!InventSerial)
    {
        InventSerial.InventSerialId = _reelNo;
        InventSerial.ItemId         = _ItemId;
        InventSerial.insert();
    }
    ttsCommit;

    select InventDimLoc where InventDimLoc.inventBatchId    == _batchNo
                           && InventDimLoc.inventSerialId   == _reelNo
                           && InventDimLoc.InventSiteId     == InventDimselect.InventSiteId
                           && InventDimLoc.InventLocationId == InventDimselect.InventLocationId
                           && InventDimLoc.ConfigId         == InventDimselect.ConfigId
                           && InventDimLoc.InventSizeId     == InventDimselect.InventSizeId
                           && InventDimLoc.InventColorId    == InventDimselect.InventColorId
                           && InventDimLoc.InventStyleId    == InventDimselect.InventStyleId
                           && InventDimLoc.wmsLocationId    == InventDimselect.wmsLocationId
                           && InventDimLoc.wmsPalletId      == InventDimselect.wmsPalletId
                            // Added License Plate & Inventory Status
                           && InventDimLoc.LicensePlateId   == InventDimselect.LicensePlateId
                           && InventDimLoc.InventStatusId   == InventDimselect.InventStatusId
                            // <GEERU>
                           && InventDimLoc.InventGtdId_RU     == InventDimselect.InventGtdId_RU
                           && InventDimLoc.InventProfileId_RU == InventDimselect.InventProfileId_RU
                           && InventDimLoc.InventOwnerId_RU   == InventDimselect.InventOwnerId_RU;
    if(InventDimLoc)
        return InventDimLoc.inventDimId;
    else
    {
        ttsBegin;
        select forUpdate InventDimLoc;
        InventDimLoc.inventDimId      = InventDim::newDimId();
        #inventDimDevelop
        InventDimLoc.ConfigId         = InventDimselect.ConfigId;
        InventDimLoc.InventSizeId     = InventDimselect.InventSizeId;
        InventDimLoc.InventColorId    = InventDimselect.InventColorId;
        InventDimLoc.InventStyleId    = InventDimselect.InventStyleId;
        InventDimLoc.InventSiteId     = InventDimselect.InventSiteId;
        InventDimLoc.InventLocationId = InventDimselect.InventLocationId;
        InventDimLoc.InventBatchId    = _batchNo;//InventDimselect.InventBatchId;
        InventDimLoc.wmsLocationId    = InventDimselect.wmsLocationId;
        InventDimLoc.wmsPalletId      = InventDimselect.wmsPalletId;
        InventDimLoc.InventSerialId   = _reelNo;//InventDimselect.InventSerialId;
        // Added License Plate & Inventory Status
        InventDimLoc.LicensePlateId= InventDimselect.LicensePlateId;
        InventDimLoc.InventStatusId= InventDimselect.InventStatusId;
        // <GEERU>
        InventDimLoc.InventGtdId_RU     = InventDimselect.InventGtdId_RU;
        InventDimLoc.InventProfileId_RU = InventDimselect.InventProfileId_RU;
        InventDimLoc.InventOwnerId_RU   = InventDimselect.InventOwnerId_RU;
        // </GEERU>
        InventDimLoc.insert(true);
        ttsCommit;

        return InventDimLoc.inventDimId;


   }

    // </GEERU>
    //inventDim.insert(true);

}


/////////////////////////////inserting new dim id in inventdim table///////////////////


        ttsBegin;
        select forUpdate InventDimLoc;
        InventDimLoc.inventDimId      = InventDim::newDimId();
        #inventDimDevelop
        InventDimLoc.ConfigId         = InventDimselect.ConfigId;
        InventDimLoc.InventSizeId     = InventDimselect.InventSizeId;
        InventDimLoc.InventColorId    = InventDimselect.InventColorId;
        InventDimLoc.InventStyleId    = InventDimselect.InventStyleId;
        InventDimLoc.InventSiteId     = InventDimselect.InventSiteId;
        InventDimLoc.InventLocationId = InventDimselect.InventLocationId;
        InventDimLoc.InventBatchId    = _batchNo;//InventDimselect.InventBatchId;
        InventDimLoc.wmsLocationId    = InventDimselect.wmsLocationId;
        InventDimLoc.wmsPalletId      = InventDimselect.wmsPalletId;
        InventDimLoc.InventSerialId   = _reelNo;//InventDimselect.InventSerialId;
        // Added License Plate & Inventory Status
        InventDimLoc.LicensePlateId= InventDimselect.LicensePlateId;
        InventDimLoc.InventStatusId= InventDimselect.InventStatusId;
        // <GEERU>
        InventDimLoc.InventGtdId_RU     = InventDimselect.InventGtdId_RU;
        InventDimLoc.InventProfileId_RU = InventDimselect.InventProfileId_RU;
        InventDimLoc.InventOwnerId_RU   = InventDimselect.InventOwnerId_RU;
        // </GEERU>
        InventDimLoc.insert(true);
        ttsCommit;



Job for generating parm methods in Axbc classes


Job for generating parm methods in Axbc classes :

static void CreateAxBCParmMethod(Args _args)
{
    axGenerateAxBCClass axGenerateAxBCClass;

    axGenerateAxBCClass = AxGenerateAxBCClass::newTableId(tablenum(InventJournalTrans));
    axGenerateAxBCClass.run();

}

Friday 3 July 2015

multi selection records in form through action type menuitem

create action menu item and add the object name as below class name"multiselectRecords"
add that menuitem in action pane and give the datasource as our datasource (Ex:prodtable)

class multiselectRecords
{
}

public static void main(Args _args)
{
    ProdTable prodtable;

    MultiSelectionHelper selection = MultiSelectionHelper::createFromCaller(_args.caller());

   prodtable = selection.getFirst();

    while (prodtable)

    {

    info(prodtable.ProdId);


        //need to do what ever lkogic here
    prodtable = selection.getNext();

    }
}


Wednesday 20 May 2015

Printer settings in ax 2012 (Print management in ax 2012)


Printer settings in ax 2012 (Print management in ax 2012):

public client static void main(Args _args, container _con)
{
    SRSPrintDestinationSettings printSettings;
    SRSPrintMediumType    printMediumType;
    SRSReportFileFormat   printFileFormat;
    FilePath              path;
    MSRouteCardController controller = new MSRouteCardController();
   
    controller.parmReportName(#ReportName);
    printMediumType = conPeek(_con,3);
    printFileFormat = conPeek(_con,21);
    path            = conPeek(_con,20);
   
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    printSettings = controller.parmReportContract().parmPrintSettings();
   
    switch(printMediumType)
    {
        case SRSPrintMediumType::Archive:
        case SRSPrintMediumType::Screen:
            printSettings.printMediumType(printMediumType);
            break;
        case SRSPrintMediumType::Printer:
            printSettings.printMediumType(printMediumType);
            printSettings.printAllPages(true);
            printSettings.fileName(@path);
            printSettings.printerName(conPeek(_con,4));
            break;
        case SRSPrintMediumType::File:
            printSettings.printMediumType(printMediumType);
            printSettings.fileFormat(printFileFormat);
            printSettings.overwriteFile(true);
            printSettings.fileName(@path);
            break;
        case SRSPrintMediumType::Email:
            printSettings.printMediumType(printMediumType);
            printSettings.emailTo(conPeek(_con,15));
            printSettings.emailCc(conPeek(_con,16));
            printSettings.emailSubject(conPeek(_con,17));
            printSettings.emailAttachmentFileFormat(conPeek(_con,18));
            printSettings.emailAttachmentImageFileFormat(conPeek(_con,19));
            break;
       
    }
    //controller.parmArgs(_args);
    //controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(true);
    controller.startOperation();
}

Note : here in container (_con) i am inserting values(print desination settings values ex :printer , email,file..etc ) in form level and passing that as parmeter to main method of controller

ex:
added a button in form level like


here setup(d) is the button. here  i added clicked method of this button as
clicked method:                                                     
void clicked()                                            
{                                                                
                                         SRSPrintDestinationSettings printJobSettings;                              
    ;                                                                  
    super();                                                      
printJobSettings = new                          SRSPrintDestinationSettings(prodParmRelease.SetupPrintDigitopiaRoutecard);
                               SrsReportRunUtil::showSettingsDialog(printJobSettings);
                                           prodParmRelease.SetupPrintDigitopiaRoutecard = printJobSettings.pack();
}      


here in this prodparmRelease is my table here i added the one container field as "SetupPrintDigitopiaRoutecard "
and this field is extended from "PrintJobSettingsPacked: