20 Temmuz 2015 Pazartesi

AXAPTA - Remove or add invent reservation

You can add or remove reservation with this code which I learned from Volkan Şişman:

  
InventUpd_Reservation       invUpdReservation; 
... 
//remove 
invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(invTrans,InventMovSubType::None),myInventDim,200,false);
            invUpdReservation.updateNow();

...
//add
          invUpdReservation = InventUpd_Reservation::newInventDim(InventMovement::construct(invTrans,InventMovSubType::None),myInventDim,400,false);
            invUpdReservation.updateNow();


Or:

//add
     InventUpd_Reservation::updateReserveBuffer(journalTrans, journalTrans.Qty);

//remove
     InventUpd_Reservation::updateReserveBuffer(journalTrans, abs(journalTrans.Qty)); 

Or:

//add

InventUpd_Reservation::newInventDim(InventTrans.inventMovement(true),InventTrans.inventDim(),-InventTrans.qty,true).updateNow();

AXAPTA - Post invent journal which it's form open

If you want to post a record like this, AX will not let you post, with an error about record is using by another. This code part I learned from Volkan Şişman lets to post:

InventJournalCheckPost      journalCheckPost;
JournalForm                 journalForm;

;
...
journalForm      = JournalForm::fromArgs(args);
journalCheckPost = InventJournalCheckPost::newFromForm(args,journalForm);
journalForm.runbaseMainStart();
journalCheckPost.run();
journalForm.runbaseMainEnd(journalCheckPost,false);

15 Temmuz 2015 Çarşamba

AXAPTA - Flexible joins with InventDim Table using InventDimExistsJoin macro

There is a macro to create flexible joins with InventDim table with easy:

InventDimParm       dimParm;
InventDim           dimValues,dimJoin;
;
...
//Fill fields to use join where condition
 dimvalues.wMSLocationId = inventdim.wMSLocationId;
    if (inventdim.InventSiteId)
        dimvalues.InventSiteId = inventdim.InventSiteId;
    if (inventdim.configId)
        dimvalues.configId = inventdim.configId;
 //Set
InventDimParm with fields
    dimparm.initFromInventDim(dimValues);

    while select lclInventSum
        where lclInventSum.ItemId == itemId && leftQty > 0
              #InventDimExistsJoin(lclInventSum.InventDimId,dimJoin,dimValues,dimParm)


First parameter was related InventDimId field for join tables, second is InventDim tables local alias, values go with third parameter. The last one is parameter table. There ara different usages of that table.

30 Haziran 2015 Salı

Axapta - Show image at grid column

In the sample we will use RefRecId field; show OK image when filled, show Cancel image when empty. For this, we write a display method to the table (or table data source of course):

 display ImageRes dispIsOKImg(gzrForeSightOrderLines l)
 {
   #resAppl;
   return l.RefRecId == 0 ? #ImageError : #Image_OK;
 }


Add a Window control to grid. At this sample it's name is LineOK. Make AlignControl of control to No. Write display method's name (for this sample is dispIsOKImg) to DataMethod, write table name (gzrForeSightOrderLines for this sample) to Datasource. Write suitable values to Height and Width. I wrote 14 both of them. If your image is so big you make ImageMode value as  Size to fit.

You will see pictures periodically refresh when run the form. For prevent this effect, you have to load images at form init:

ClassDeclaration method:
ImageList                           imageList;

Init method:
#resAppl
imageList = new Imagelist(Imagelist::smalliconWidth(),Imagelist::smalliconHeight());
imagelist.add(new image(#Image_OK));
imagelist.add(new image(#ImageError));
LineOK.imageList(imageList);


change return line like this at the Display method:

return l.RefRecId == 0 ? 1 : 0;

To see/update image list at resAppl macro:

AOT->Macros->ResAppl->Edit

To see all image resources at the system Tools->Development tools-> Embedded resources.

10 Şubat 2015 Salı

C# - Create COM compatible DLL and use without app.config file with a web service consume

You can make your DLL as COM compatible a way which I learned from an article:


[ComVisible(true)] 

Also Register for COM interop checkbox should be checked from project properties->build page.

You can use Intellisense when using COM object with this:

[ClassInterface(ClassInterfaceType.AutoDual)] 

After all you can use DLL yet from your COM compatible language (except there is no binding). When you try to use you get an error; "OLE IDispatch exception code 0 from System.ServiceModel: ServiceModel...". You have to copy app.config file as yourexefile.EXE.app.config or add these red code parts to your class (I got help for this from Paul Mrozowski):

For add this sample web service to your project, you have to right click at Service References than Add Service Reference-> write https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx to address and push GO.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.ServiceModel;



namespace TCKimlik
{
    [ComVisible(true)] //for visible COM object
    [ClassInterface(ClassInterfaceType.AutoDual)] //for intellisense at using COM
    [ProgId("TCKimlik.TCSorgula")] //COM object name
   
    public class TCKimlikClass
    {
        public bool Dogrula(string adi,string soyadi,Int64 tc,Int32 dogumT)
        {
            bool ret = false;

            //------ for using COM compatible DLL without APP.CONFIG
            BasicHttpsBinding binding = new BasicHttpsBinding();
            EndpointAddress address = new EndpointAddress("https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx");

            //------ run --------
                try
            {
                Sorgula.KPSPublicSoapClient servis = new Sorgula.KPSPublicSoapClient(binding, address);

                ret = servis.TCKimlikNoDogrula(tc, adi, soyadi, dogumT);
            }
            catch
            {
            }
            return ret;
        }
    }
}


Now you can use this DLL at COM compatible languages plus .NET. But if you move DLL to client computer without setup you have to register with regasm. I  shared project.

There is a sample usage with Microsoft Visual Foxpro:

o=CREATEOBJECT("tckimlik.tcsorgula")
?o.Dogrula("METİN","EMRE",11111111111,1980)

23 Ocak 2015 Cuma

JAVASCRIPT - Solve 403.14 - Forbidden error

I intended learn to Javascript and got "HTTP Error 403.14 - Forbidden..." error at first try. I found the solution from a blog. Move to "C:\Program Files\IIS Express" (It may different at your computer) folder and run this command:

appcmd set config /section:system.webServer/directoryBrowse /enabled:true

2 Ocak 2015 Cuma

SQL SERVER - If noone has Sysadmin rights or SA password is lost?

Go to pproperties of relates servers from SQL Server Configuration Manager. Advanced->Properties than put "-m" parameter. Carefull about you have to put ";" after last parameter and put no space! I mean ";-m" (Without quotes).
Restart to SQL Server. Server will run in single mode.
Run SQLCMD.EXE as administrator. Give Sysadmin rights to your Windows user which you use at login for your SQL Server:
EXEC sp_addsrvrolemember "myserver\myuser","sysadmin";
GO


or

EXEC sp_password NULL, 'newpwd', 'sa';
GO

Don't forget delete parameter and restart server at regular mode!..

Source:
http://blogs.msdn.com/b/raulga/archive/2007/07/12/disaster-recovery-what-to-do-when-the-sa-account-password-is-lost-in-sql-server-2005.aspx