Monday 23 November 2015

Partial Packingslip using code in ax 2012

static void Job49(Args _args)
{
   salesLine salesLine;
   salesFormLetter salesFormLetter;
   SalesTable salestable;
   ;
   ttsbegin;
   //update Sales Line
   salestable = salestable::find('DSB-0000001089');
   salesLine = SalesLine::find('DSB-0000001089', 1, true);  // find the item id
   salesLine.SalesDeliverNow   = 1;
   salesLine.setInventDeliverNow();
   salesLine.doUpdate();
   //Post the delivery note
   salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
   //salesFormLetter.progressHide();                                // Hide the progress bar.
   salesFormLetter.update(salesTable,                             // SalesTable
                       SystemDateGet(),                        // Delivery date
                       SalesUpdate::DeliverNow,                // Quantity to update (SpecQty)
                       AccountOrder::None,                     // AccountOrder
                       false,                                  // Proforma only?
                       false);                                 // Printout?
    ttsCommit;

}

Filteration on Rownumber in SSRS

To do some operation on the basis of rownumber we can use the RowNumber function of the SSRS

=iif(RowNumber(Nothing) Mod 2,”Green”,”Yellow”).

on the above line it will fill the line color as green adn yellow on the basis of odd even linbes

=iif(RowNumber(Nothing) = 1,”Yes”,”No”).

above line will visible only first line

nothing will consider the outer most group for filteration

UAC setting

Goto ControlPanel -> User account

 
click on Change User Account Control setting


make it minimum.

Attachment Button on new form


Step 1. Open your form in AOT and Go to from Design node.

Step 2. Add new button group under ActivePanTab.

Step 3. Add new command button under this new button group.

clip_image001

Step 4. Set following properties of this button

clip_image002

Now you need to do one functional setup for this new customization

Step 5: Open below from
Organization administration/SetUp-> Document Management -> Active Document Table

Step 6: Add your table details here and click on Always enable.

clip_image003

Step 7: So its done now.

 Open your form and click on Attachment button , below form must open.

clip_image006

Read and Write files using Excel


WRITE

static void Write2ExcelFile(Args _args)
{

InventTable inventTable;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;

application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
cells.range('A:A').numberFormat('@');

cell = cells.item(1,1);
cell.value("Item");
cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
application.visible(true);
}

READ


Reading Data from Excel File
static void ReadExcel(Args _args)
{

SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
ItemId itemid;
Name name;
FileName filename;


;

application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = "C:\\item.xls";
try
{
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();
do
{
row++;
itemId = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
info(strfmt('%1 - %2', itemId, name));
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}

FtpWebRequest

Upload File

   System.Object ftpo;
   System.Object ftpResponse;
   System.Net.FtpWebRequest request;
   System.IO.StreamReader reader;
   System.IO.Stream requestStream;
   System.Byte[] bytes;
   System.Net.NetworkCredential credential;
   System.String xmlContent;
   System.Text.Encoding utf8;
   System.Net.FtpWebResponse response;
   ;
   // Read file
   reader = new System.IO.StreamReader("C:/test.xml");
   utf8 = System.Text.Encoding::get_UTF8();
   bytes = utf8.GetBytes( reader.ReadToEnd() );
   reader.Close();
   // little workaround to get around the casting in .NET
   ftpo = System.Net.WebRequest::Create("ftp://ftp.company.com/dir/test.xml");
   request = ftpo;
  
   credential = new System.Net.NetworkCredential("user","password");
   request.set_Credentials(credential);
   request.set_ContentLength(bytes.get_Length());
   request.set_Method("STOR");
   // "Bypass" a HTTP Proxy (FTP transfer through a proxy causes an exception)
   // request.set_Proxy( System.Net.GlobalProxySelection::GetEmptyWebProxy() );
   requestStream = request.GetRequestStream();
   requestStream.Write(bytes,0,bytes.get_Length());
   requestStream.Close();
  
   ftpResponse = request.GetResponse();
   response = ftpResponse;
   info(response.get_StatusDescription());
 
 

Read from FTP

   System.Object ftpo;
   System.Net.FtpWebRequest request;
   System.IO.StreamReader reader;
   System.Net.NetworkCredential credential;
   System.Net.FtpWebResponse response;
   System.String text;
   ;
   ftpo = System.Net.WebRequest::Create("ftp://ftpserver.com/dir/myfile.txt");
   request = ftpo;
   credential = new System.Net.NetworkCredential("user","password");
   request.set_Credentials(credential);
   response = request.GetResponse();
   reader = new System.IO.StreamReader(response.GetResponseStream());
   text = reader.ReadToEnd();
   info(text);