Rahulvarshney's Blog

April 30, 2010

Error “ClrObject static method invocation error.” during use of WINAPI class method Copyfile() in axapta

Filed under: ax,Ax2009,Axapta,Microsoft Dynamics Axapta — rahulvarshney @ 9:42 am
Tags: , , , ,

Hi All,

If  you have requirement to copy files from some folder[Target folder] to your specified folder[destination]  then usually we use WinApi class CopyFile() method but this method will not work if you sub-folders in your Target folder then it will show error “ClrObject static method invocation error.”.

To resolve this error first we need to check whether the file you are going to copy is a folder or file that we can do by using WINAPI::folderExists().The correct way to do this as below:

public void copy(FilePath _filePath)
{
int         firstFileHandle;
Filename    filenameCurrent;
FilePath    parentDir = @’D:/tmp’;
;

//winApi::setCurrentDirectory(_filePath);
[firstFileHandle,filenameCurrent] = Winapi::findFirstFile(_filePath + ‘/’ + ‘*.*’);
while(filenameCurrent)
{
IF(filenameCurrent != ‘.’ && filenameCurrent != ‘..’)
{
if(WinApi::fileExists(_filePath + ‘/’ + filenameCurrent, false))
winapi::copyFile(_filePath + ‘/’ + filenameCurrent,@’D:/test/’+filenameCurrent,true);
else if(WinAPi::folderExists(filenameCurrent))
{
this.copy(parentDir + ‘/’ + filenameCurrent);
}
}
filenameCurrent = winapi::findNextFile(firstFileHandle);
}
}

_filePath : path where you want to copy files

Note : This code will work only if you create this method in class it will not work in Jobs

April 27, 2010

formrun.dataSource().findRecord(….) takes more time to open Form

Filed under: ax,Ax2009,Axapta,Microsoft Dynamics Axapta — rahulvarshney @ 5:56 am
Tags: , , , ,

Hi all,

For some of the requirements we have to override method Jumref() and need to call form from there and for highlighting the selected record on opened form we need to call formrun.dataSource().findRecord(….) method but if you have plenty of data in your form which you want to open then some times form will become hanged so to prevent this we need to use lookupfield() and lookupvalue() methods of Args Class.

you can change your code as below:

old code:

Args args;
SysSetupFormRun formRun;
;
args = new Args(formStr(CustTable));
formRun = classfactory.formRunClass(args);
formrun.init();
formrun.run();
formrun.dataSource().findRecord(CustTable::find(CustCollectionLetterJour.AccountNum));
formrun.detach();

New Code:

args = new Args(formStr(CustTable));
args.lookupField(fieldNum(CustTable, AccountNum));
args.lookupValue(CustCollectionLetterJour.AccountNum);

formRun = classfactory.formRunClass(args);
formrun.init();
formrun.run();
formrun.detach();

Create a free website or blog at WordPress.com.