Thursday, 24 March 2016

Refresh DataSource and retain position

http://devexpp.blogspot.in/2012/02/refresh-datasource-and-retain-position.html

int position;
    ;
    position = myTable_ds.getPosition();
    myTable_ds.research();
    myTable_ds.setPosition(position);

Friday, 18 March 2016

Add Document Attachment to the record

static void addDoc( Common common,
                    DocuTypeId docuTypeId,
                    FileName fileName)
{
    DocuRef docuRef;
    DocuValue docuValue;
 
    if(common && docuTypeId)
    {
        ttsBegin;
        docuRef.clear();
        docuRef.initValue();
        docuRef.TypeId = docuTypeId;
        docuRef.Name = filename;
        docuRef.RefRecId = common.RecId;
        docuRef.RefTableId = common.TableId;
        docuRef.RefCompanyId = curext();
        docuValue.initFromDocuRef(docuRef);
        docuValue.insert();
        docuRef.ValueRecId = docuValue.RecId;
        docuRef.insert();
        ttsCommit;
        if(filename)
        {
            DocuValue::writeDocuValue(docuRef,filename); //after ttsCommit to enable catching of file system errors
        }
    }
}

How to get report caption different when we execute same report in different scenarios

Hi ,

I have a  requirement, like when I execute my report it should get different caption at different places.

When we run through Controller Class :

Modify the controller class, with two methods :

public container pack()
{
    container con;

    con  = super();

    return con;
}

public boolean unpack(container packedState)
{
    boolean ret;

    ret = super(packedState);

    this.parmDialogCaption(this.parmArgs().record().TableId  ==  tableNum(SalesTable) ? "@CIT467" : "@CIT130");

    return ret;
}


So in above condition,  based on arguments record it displays different names when i execute the report.

So below is the link for reference :
https://nasheet.wordpress.com/tag/ssrs-reporting-in-ax/

When we call the report through X++ code directly the menu item  below is the code :
static void ReportRun(Args _args)
{
    SrsReportRun srsReportRun;
    srsReportRun = new SrsReportRun("ItemLabelReport.Report");

    srsReportRun.init();
    srsReportRun.reportCaption("InventOnHand");
    srsReportRun.showDialog(false);
    if( srsReportRun )
    {
    srsReportRun.executeReport();
    }
    info("Report Saved");
}

Thursday, 10 March 2016

How to delete duplicate records through ax 2012

To delete duplicate records from salesTable or any other table through ax 2012 by x++ code you  can write code in AX job.

Set fieldSet = new set(Types::Integer);

DictIndex  IndexName  = new DictIndex(tablenum(SalesTable),indexnum(SalesTable,SalesIdx));

int i;
;
if(IndexName.numberOfFields())
{
for(i=1;i<=IndexName.numberOfFields();i++)
{
fieldSet.add(IndexName.field(i));
}

ReleaseUpdateDB::indexAllowDup(IndexName);
ReleaseUpdateDB::deleteDuplicatesUsingIds(SalesTable),0,fieldSet);
ReleaseUpdateDB::indexAllowNoDup(IndexName):
}

info("Duplicate Records deleted successfully");

How to Add a Filter to a List Page in axapta

You can add filter controls to FilterPaneGroup and filter list page query based on your requirement.
Below is the link to follow the steps.

http://msdn.microsoft.com/en-us/library/cc577231(v=ax.50).aspx

How to disable a query range from user

Sometimes we do not want the user to change the query range on a form or a  report.
To hide this from user, we need to write the following code for the range of the query.
In my case I have written a queryrange on the init() method of the datasource in a form.


    queryRange = this.query().dataSourceTable(TableNum(CustTable))
                          .addRange(fieldnum(CustTable,CustStatus));
    queryRange .value('close');
    //to make the field uneditable use the following code
    queryRange .status(1);

 Reference: http://support.microsoft.com/kb/910958

How to use entry point security in x++ based on a record

I had one requirement where in Sales order form the records which are confirmed must not be allowed to edit for a user role. This can be resolved by two ways:


1. To check the current user role and making the edit button as false on a condition,override active method of datasource and code as below:

select role
        where role.Name == 'RoleName'
    join userRole
        where userRole.SecurityRole == role.RecId
            && userRole.User == curUserId();
    if(userRole && SalesTable.DocumentStatus == DocumentStatus::Confirmation)
    {
    editButtonAllow= false;
    }

2. To avoid hard coding the Roles, we can use an entry point and check users access to the entry point

we need to create a menu item with a privilege and duty assigned to a role, override active method of datasource and use the menu item as below:

SecurityRights      sr;
AccessRight         accessRight = AccessRight::View;
sr = SecurityRights::construct();

accessRight = sr.menuItemAccessRight(SecurableType::MenuItemAction,menuitemActionstr(MenuItemName));
if(accessRight == AccessRight::View && SalesTable.DocumentStatus == DocumentStatus::Confirmation)
{
    ButtonName.enabled(false);
}
 else
 {
    ButtonName.enabled(true);
  }