Skip to main content

Posts

Showing posts from September, 2012

Send mail via populate the outlook client by code in MSD axapta

To Send mail via populate the outlook client by code in axapta #ObjOutlookCOMDEF #define.outlook("Outlook.Application") #define.mapi("MAPI") COM ObjOutlook; COM ObjOutlookNameSpace; COM ObjOutlookMailItem; COM ObjOutlookAttachment; COM ObjOutlookRecipient; ; ObjOutlook = new COM(#outlook); ObjOutlookNameSpace = ObjOutlook.getNamespace(#mapi); ObjOutlookNameSpace.logon(); ObjOutlookMailItem = ObjOutlook.CreateItem('Outlook.OlItemType.olMailItem'); ObjOutlookMailItem.To("sksinght@abc.com"); ObjOutlookMailItem.Subject("Testing"); ObjOutlookAttachment = ObjOutlookMailItem.Attachments(); ObjOutlookAttachment.Add(@"d:\xyz.pdf",1,1,"New"); ObjOutlookMailItem.save(); ObjOutlookMailItem.display(); info("Activity launched in Microsoft Outlook"); ObjOutlookNameSpace.logoff();

How to insert tableid using Insert recordset in MSD axapta

How to insert tableid using Insert_recordset. Its work on latest version of dynamics ax only. int tab2 = tableNum(Table2); insert_recordset TABLE(RefRecId, RefTableId) select recId, tab2 from Table2 Syntax.. insert_recordset NameOfTable(field1, field2,field3,field4,field5) select field1, field2,field3,field4,field5 from RecOfTable where Concolm<=299999; //In SQL you can execute this way to work faster. SELECT * INTO table2 FROM table1;

How to remove special characters from string in MSD axapta

To remove special characters from string in axapta you can try following code . static void formatedString(Args _args) { str StringVal = “ Hello \tSumit \n Dear”; str replace(str _sourceStr, str _what, str _with) { int found = 0; str target = _sourceStr; ; do { found = strscan(TargetStr, _what, found, strlen(TargetStr)); if (found != 0) { TargetStr = strdel(TargetStr, found, strlen(_what)); TargetStr = strins(TargetStr, _with, found); found += strlen(_with); } } while (found != 0); return TargetStr; } ; StringVal = replace(StringVal, ‘\n’, ”); StringVal = replace(StringVal, ‘\r’, ”); StringVal = replace(StringVal, ‘\t’, ”); StringVal = replace(StringVal, ‘ ‘, ”); info(StringVal); }

Add sort field on grid using form datasource in MSD axapta

To Add sort field on grid using form data source in axapta  you can do following code in form data source table on execute query method. public void executeQuery() {; InventTable_ds.query().dataSourceNo(1).sortClear(); InventTable_ds.query().dataSourceNo(1).addSortField(fieldNum(CustTable,CustGroup), sortOrder::Ascending); super(); } After adding code you can call in modified method of control or init method of form. public boolean modified() { boolean ret; ; ret = super(); InventTable_ds.executeQuery(); return ret; }

ttsBegin and ttsCommit in MSD axapta

You can use ttsbegin and ttscommit with ttsabort following way. You can try in job public boolean myMethod() { try { ttsBegin; select forUpdate myTable; myTable.fname = testt_; myTable.update(); ttsCommit; } catch(exception::Error) { ttsabort; return(false); } return(true); }

Error on deploying the ssrs reports for reporting services in MSD axapta

If you are getting following Error on deploying  the ssrs reports for reporting services in axapta . could not load file or assembly 'microsoft.dynamics.kernel.cli ent. You can try following step to resolve this error. 1. copy the AXReports.exe file place to the folder: c:\Program files\Microsoft Dynamics AX\50\Client\Bin, and registering the Microsoft.Dynamics.Kernel.Client file in the GAC by dragging and dropping the file to the folder: c:\windows\assembly. 2. Checke for user permission issues. 3. Check whether  Reporting service SIte Link Working or not.

Sale order table structure in MSD axapta

If you want to know sales order table flow then you need to know following flow. for customer following table user Custparameter CustTable, CustGroup. Sales Order front screen table SalesTable->SalesParmtable SalesLine->Sale order table structure in axapta After posting data goes to CustInvoiceJour CustInvoiceTrans CustTrans Financial voucher effect goes to LedgerTrans. InventTrans Table is common table for all inventory.

Example of sending mail in MSD Ax

To send mail you can try code in following way in job . You can then set this code in your way in form or dialog . str sendereml = 'sendereml@domainname.com'; str recipienteml= 'recipient@domainname.com'; str cc1 = 'cc@domainname.com'; str subject = 'Testing'; str MailBody = 'Testing mail txt -hello how r u'; str fileName1 = @'C:\Testing1.txt'; Set permissionSet; System.Exception e; str mailServer; System.Net.Mail.SmtpClient mailClient; System.Net.Mail.MailMessage mailMessage; System.Net.Mail.MailAddress mailFrom; System.Net.Mail.MailAddress mailTo; System.Net.Mail.MailAddressCollection mailCCCollection; System.Net.Mail.AttachmentCollection mailAttachementCollection; System.Net.Mail.Attachment mailAttachment; ; try { permissionSet = new Set(Types::Class); permissionSet.add(new InteropPermission(InteropKind::ClrInterop)); permissionSet.add(new FileIOPermission(filename1, &#

How to get the address of customer in a single line in Report in MSD axapta

To get the address field of customer in a single line in Report or form in axapta you can get hints by following code. DirPartyId partyId; DirPartyAddressRelationship dirPartyAddressRelationship; DirPartyAddressRelationshipMapping dirPartyAddressRelationshipMapping; Address address; str resultAddress; ; partyId = DirPartyTable::find(CustTable::find('1101').PartyId).PartyId; select dirPartyAddressRelationship where dirPartyAddressRelationship.PartyId == partyId; select dirPartyAddressRelationshipMapping where dirPartyAddressRelationshipMapping.PartyAddressRelationshipRecId == dirPartyAddressRelationship.RecId; select address where address.dataAreaId == dirPartyAddressRelationshipMapping.RefCompanyId && address.RecId == dirPartyAddressRelationshipMapping.AddressRecId; resultAddress = address.Street+" "+address.City+", "+address.State+" "+address.ZipCode+" "+address.CountryRegionId;

Send message from one computer to other by MS Dynamics axapta code

To Send message from one computer to other by Dynamics axapta code you can try following code in ax job. COM netSendComObj; InteropPermission InteropPermission1 = new InteropPermission(InteropKind::ComInterop); int Result; str NameOfMachine = Winapi::getComputerName(); str MSG = ‘Hello how are you.Do you know me I am Dynamics AX’; InteropPermission1.assert(); try { netSendComObj = new COM("WScript.Shell"); Result = netSendComObj.Run(strFmt("net send %1 %2", NameOfMachine, MSG),0,true); } catch (Exception::Error) { CodeAccessPermission::revertAssert(); throw Exception::Error; } if (Result != 0) { warning(strfmt(‘Sending message Failed’, NameOfMachine)); warning(‘Check messenger service is Started’); } CodeAccessPermission::revertAssert();    

Message in event log using Microsoft dynamics axapta code

To  Write message in event log by dynamics axapta code x++ you can try following code in job of AOT. System.Diagnostics.EventLog EventLogObj = new System.Diagnostics.EventLog(); ; EventLogObj.set_Source(‘Dynamics Axapta -Message from Admin’); EventLogObj.WriteEntry("This is just checking of message in event log form Dynamics ax"); EventLogObj.Close();

Start and stop windows services in MSD axapta by code

To Start and stop service in axapta by code You first add  reference System.Service Process in Application Object tree (AOT) on reference node after doing this you can add following code in job. System.ServiceProcess.ServiceController ServiceController1 = new System.ServiceProcess.ServiceController(); ; ServiceController1.set_MachineName(‘.’); ServiceController1.set_ServiceName("IISADMIN"); ServiceController1.Stop(); sleep(500); ServiceController1.Start();

How to show value in dialog on the basis of other field in MSD axapta

To show value in dialog on the basis of other field in axapta , you can try  code in report following way. public class Test extends ObjectRun { DialogField dlgfld1,dlgfld2; InventLocationId _InventLocationId; Name _name; } public Object dialog(Object _dialog) { DialogRunbase dialog = _dialog; ; dialog.caption('Location Details'); dialog.addGroup('Select Location Id :'); dlgfld1 = dialog.addField(typeid(_InventLocationId),"Location Id : "); dlgfld1.value(_InventLocationId;); dlgfld2 = dialog.addField(typeid(_Name),"Location name : "); dialog.allowUpdateOnSelectCtrl(true); return dialog; } public void dialogSelectCtrl() { ; dlgfld2.value(InventLocation::find(dlgfld1.value()).Name); } boolean getFromDialog() { ; _InventLocationId; = dlgfld1.value(); _name = dlgfld2.value(); return true;. }

How to Assign one user rights to other user by code in MSD axapta

You can try following code in Job or you can apply in form controls event. UserGroupList UsergroupList1,UsergroupList2; UserId FromUserId, ToUserId; ; FromUserId = 'usr1'; ToUserId = 'usr2' ; delete_from UsergroupList1 where UsergroupList1.UserId == ToUserId; while select UsergroupList1 where UsergroupList1.userId == FromUserId { info(strfmt('Group assigned: %1',UsergroupList1.groupId)); select forupdate UsergroupList2 where UsergroupList2.userID == ToUserId && UsergroupList2.GroupId == UsergroupList1.GroupId; if(!UsergroupList2) { UsergroupList2.UserId = ToUserId; UsergroupList2.GroupId = UsergroupList1.GroupId; UsergroupList2.insert(); } } info(strfmt('Permissions changed for %1',ToUserId));

How to get Location of folder of MS dynamics axapta and windows folder

xInfo::directory(DirectoryType::Bin); xInfo::directory(DirectoryType::Temp) xInfo::directory(DirectoryType::Include); xInfo::AOTLogDirectory(); xInfo::directory(DirectoryType::Help); xInfo::directory(DirectoryType::APPL); For windows you can try these command WinApi::getTempPath() WinAPI::getFolderPath(#CSIDL_INTERNET_CACHE); WinAPI::getFolderPath(CSIDL_DESKTOPDIRECTORY);

Get current date in differert way by MSD axapta

How to Get current date in differert way by axapta info(date2str(today(),123,2,2,2,2,4)); //This method will show you date of the machine. There is no support of time. info(date2str(systemdateget(),123,2,2,2,2,4)); //This method will show you current system session date.You can change session date under tool //session menu. //Following are mehtod for to show date with time . Juse use and see it. info(date2str(DateTimeUtil::date(DateTimeUtil::getSystemDateTime()),123,2,2,2,2,4)); info(date2str(DateTimeUtil::date(applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone())),123,2,2,2,2,4));

How to import xpo in MSD axapta by code

How to import xpo in axapta by code. You can write following code in job or any where you want to import like form,class,report etc. SysImportElements ElementToImport = new SysImportElements(); ; ElementToImport.newFile("D:\\TestProject.xpo"); // XPO filename which may be project,form,report or any thing from aot ElementToImport.parmImportAot(true); ElementToImport.parmImportWithIds(false); ElementToImport.import(); You write this code in method or can directly write in overridden method clicked  on button control.