example code to fix it :
hcmEmploymentEmployee.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
example code
public static DimensionDynamicAccount defaultDimension2ledgerDimension(LedgerJournalAC _ledgerJournalAC,DimensionDefault _defaultDimension ) { container conDimName; container conDimValue; int loop = 1; DimensionValue dimValue; Name dimName; DimensionServiceProvider DimensionServiceProvider = new DimensionServiceProvider(); LedgerAccountContract LedgerAccountContract = new LedgerAccountContract(); List ListValueContract = new List(Types::Class); DimensionAttributeValueContract ValueContract; dimensionAttributeValueCombination dimensionAttributeValueCombination; DimensionStorage dimStorage; conDimName = Global::getDimensionNameTID(); while(loop <= conLen(conDimName)) { dimName = conPeek(conDimName,loop); dimValue = Global::getDimensionValueTEC(_defaultDimension,dimName); if(dimValue) { ValueContract = new DimensionAttributeValueContract(); ValueContract.parmName(dimName); ValueContract.parmValue(dimValue); ListValueContract.addEnd(ValueContract); } loop++; } LedgerAccountContract.parmMainAccount(_ledgerJournalAC); LedgerAccountContract.parmValues(ListValueContract); dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract); dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save()); return dimensionAttributeValueCombination.RecId; }
this below is a custom method on global class.. (or you can put it on other class)
public static container getDimensionNameTID() { DimensionAttribute dimAttr; DimensionAttributeSetItem dimAttrSetItem; DimensionEnumeration dimensionSetId; DimensionAttributeValue dimAttributeValue; container DimensionName; dimensionSetId = DimensionCache::getDimensionAttributeSetForLedger(); while select dimAttr order by Name where dimAttr.Type != DimensionAttributeType::MainAccount join RecId from dimAttrSetItem where dimAttrSetItem.DimensionAttribute == dimAttr.RecId && dimAttrSetItem.DimensionAttributeSet == dimensionSetId { dimensionName += dimAttr.Name; } return DimensionName; }
this below is a custom method on global class.. (or you can put it on other class)
public static str 255 getDimensionValueTEC(RecId defaultDimension, Name dimName) { DimensionAttributeValueSetStorage dimStorage; Counter i; DimensionAttribute dimAttributeCostCenter; DimensionAttributeValue dimAttributeValue; dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension); return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId); }
example code :
public static void autoSettlementJournalFromPAYDetails(JournalId _journalNum) { CustVendOpenTransManager manager; CustTrans custTrans; CustTransOpen custTransOpen; LedgerJournalTrans ledgerJournalTrans; AxLedgerJournalTable axLedgerJournalTable; AxLedgerJournalTrans axLedgerJournalTrans; ExchangeRateHelper exchangeRateHelper; AmountCur totalSettleAmount; AmountCur amountCurDebit,amountCurCredit; HRSPayJournalDetails hrsPayJournalDetails; HRSPayJournalTable hrsPayJournalTable; int Row; AxLedgerJournalTable = AxLedgerJournalTable::newLedgerJournalTable(LedgerJournalTable::find(_journalNum)); ttsBegin; //details journal lines from Pay Journal Details while select hrsPayJournalTable join hrsPayJournalDetails where hrsPayJournalTable.HRSPayJournalId == hrsPayJournalDetails.HRSPayJournalId && HRSPayJournalTable.JournalNum == _journalNum { CustTrans = CustTrans::findFromInvoice(hrsPayJournalDetails.ReferenceNumber,HRSPayJournalDetails.AccountNum); CustTransOpen = CustTransOpen::findRefId(CustTrans.RecId); if(CustTransOpen) { //Create Trans ... axLedgerJournalTrans = new axLedgerJournalTrans(); axLedgerJournalTrans.parmJournalNum(AxLedgerJournalTable.ledgerJournalTable().JournalNum); axLedgerJournalTrans.parmTransDate(today()); axLedgerJournalTrans.parmDue(today()); axLedgerJournalTrans.parmAccountType(LedgerJournalACType::Cust); axLedgerJournalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount(hrsPayJournalDetails.AccountNum, LedgerJournalACType::Cust)); axLedgerJournalTrans.parmAmountCurCredit(hrsPayJournalDetails.Credit); axLedgerJournalTrans.parmAmountCurDebit(hrsPayJournalDetails.Debit); axLedgerJournalTrans.save(); manager = CustVendOpenTransManager::construct(axLedgerJournalTrans.ledgerJournalTrans()); manager.updateTransMarked(custTransOpen,true); if(hrsPayJournalDetails.Debit) { manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Debit); } else { manager.updateSettleAmount(custTransOpen,hrsPayJournalDetails.Credit); } //update after settle ledgerJournalTrans = axLedgerJournalTrans.ledgerJournalTrans(); ledgerJournalTrans.selectForUpdate(true); ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact; ledgerJournalTrans.update(); Row++; } } ttsCommit; info(strFmt("Total Lines settled : %1",Row)); }
it is common for user to search item based on name. but currently on AX 2012, onHand form can’t provide search based on item name or search name. It will take a little modification from technical side.
example how to do it :
1. you can join directly on form datasource or create view like example (i’m using the view that already created for another purpose)
2. on InventSumTable add relations like this.
3. then go to form onHand (InventOnHandItem), and add the view to datasource
4. open class InventDimCtrl_Frm_OnHand and modify method modifyQuery , on class declaration parameter, add new parameter FormDataSource with default null parameter. then define new variable QueryBuildDataSource.
5. on the last line of the method modifyQuery , add code like example :
if(_tidInventLookUp) { qbsInventLookup = query.dataSourceName(_tidInventLookUp.name()); //filter current company language qbr = SysQuery::findOrCreateRange(qbsInventLookup, fieldnum(TIDInventLookup, LanguageId)); qbr.value(queryValue(CompanyInfo::languageId())); qbsInventLookup.addGroupByField(fieldNum(TIDInventLookup,Name)); qbsInventLookup.addGroupByField(fieldNum(TIDInventLookup,NameAlias)); }
5. then back to the form, on datasource inventSUm, on executeQuery , modify the code from
void executeQuery() { element.inventDimSetupObject().modifyQuery(inventSum_DS,inventDim_DS); super(); }
to
void executeQuery() { element.inventDimSetupObject().modifyQuery(inventSum_DS,inventDim_DS,TIDInventLookUp_ds); super(); }
6. drag the field from newly add datasource on form to the grid :
7. Voila done, example result, :
note: remember to GROUPBY on code if you add new field to the form, or the field on form will show “UNRETRIEVED”
public void initializeQuery(Query _query) { // ListPageLabelChange => Common externalRecord; FormDataSource frmDs; FormRun formRun; FormControl frmCtrl; // ListPageLabelChange <= _query.dataSourceTable(tableNum(HRSBenefitEntitlement)).addRange(fieldNum(HRSBenefitEntitlement,Employment)).value(SysQuery::value(HcmEmployment::findByWorkerLegalEntity(HcmWorker::userId2Worker(curUserId()),CompanyInfo::find().RecId).RecId)); super(_query); // ListPageLabelChange => externalRecord = this.listPage().activeRecord(_query.dataSourceTable(tableNum(HRSBenefitEntitlement)).name());//No intrisic function for form DS? if(externalRecord.isFormDataSource()) { frmDs = externalRecord.dataSource(); formRun = frmDs.formRun(); if(formRun) { frmCtrl = formRun.design().controlName(formControlStr(TIDBenefitEntitlementListPage,HRSBenefitEntitlement_Entitlement)); if(frmCtrl) { frmCtrl.userPromptText("newName"); } } } // ListPageLabelChange <= }
clear usage data if no changes on form.
public client static void processMDBData(str _StrDSN, str _StrTableName, date _DateFrom, date _DateTo) { #AviFiles SysOperationProgress progress = new SysOperationProgress(); OdbcConnection C; Statement S; LoginProperty LP = new LoginProperty(); ResultSet RS; HcmPersonnelNumberId _EmplID; TimeHour24 _Time; str strquery,strDSN,tableName; Date _Date; int Idx; HRSTMAttendanceTemp attDataTemp; ; try { strDSN = _StrDSN; tableName = _StrTableName; ttsbegin; LP.setDSN(_strDSN); LP.setServer("S-AOS1TEST"); C = new OdbcConnection(LP); S = C.createStatement(); strquery = strFmt("SELECT * FROM %1 where dateLog >= #%2# AND dateLog <= #%3#",tableName,_DateFrom,_DateTo); RS = S.executeQuery(strquery); while (RS.next()) { //Progress.incCount(); _EmplID = Rs.getString(1); _Date = RS.getDate(2); _Time = str2time(RS.getString(3)); Idx = str2int(rs.getString(4)); //insert to temp table if(_EmplID == '') continue; select forupdate attDataTemp where attDataTemp.PersonnelNumber == _EmplID && attDataTemp.Time == _Time && attDataTemp.TransDate == _Date; if(!attDataTemp) { attDataTemp.clear(); attDataTemp.PersonnelNumber = _EmplID; attDataTemp.Time = _Time; attDataTemp.TransDate = _Date; attDataTemp.Idx = Idx; attDataTemp.insert(); } else { attDataTemp.Idx = Idx; attDataTemp.ClockId = ''; attDataTemp.update(); } Progress.setText(strfmt("Upload Id %1 - %2 %3", _EmplID, _date, time2str(_time, 1, 1))); } ttsCommit; } catch { ttsAbort; return; } }
HcmEmployment::findByWorkerLegalEntity(HcmWorker::userId2Worker(curUserId()),CompanyInfo::find().RecId).RecId
example code :
public static void main(Args _args) { recID recID = _args.record().RecId; tableId tableId = _args.record().TableId; HcmEmploymentLeave HcmEmploymentLeave = _args.record(); WorkflowWorkItemTable workItem = _args.caller().getActiveWorkflowWorkItem(); str menuItemName = _args.menuItemName(); WorkflowWorkItemActionDialog workflowWorkItemActionDialog; WorkflowSubmitDialog workflowSubmitDialog; Debug::assert(tableId == tablenum(HcmEmploymentLeave)); Debug::assert(recId != 0); // The method has not been called correctly. if (tableId != tablenum(HcmEmploymentLeave) || recId == 0) { throw error(strfmt("@SYS19306", funcname())); } // The journal has an active workflow. if (workItem.RecId > 0) { try { // The journal does support workflow approvals. workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct( workItem, WorkflowWorkItemActionType::Resubmit, new MenuFunction(_args.menuItemName(),_args.menuItemType())); workflowWorkItemActionDialog.run(); if (workflowWorkItemActionDialog.parmIsClosedOK()) { workItem = _args.caller().getActiveWorkflowWorkItem(); WorkflowWorkItemActionManager::dispatchWorkItemAction( workItem, workflowWorkItemActionDialog.parmWorkflowComment(), workflowWorkItemActionDialog.parmTargetUser(), WorkflowWorkItemActionType::Resubmit, _args.menuItemName(), false); } } catch(Exception::Error) { throw error(strfmt("Leave %1 can't be submitted", HcmEmploymentLeave.HRSLeaveReqId)); } } // Make the form refresh its common workflow UI controls. _args.caller().updateWorkflowControls(); }
example code :
if (box::yesNo('The data on temp table will be process, are you sure ?', dialogButton::Yes, 'Confirmation') == dialogButton::Yes) { HRSPopulateTimeAttendance.run(); }
i found this error when i tried deploying cube via ax wizard.
how to fixed error :
1. Just run the analysis service as admin domain or user domain that have the right priveleges. Set it up on SQL Server Management Configuration.
related source :
1. https://msdn.microsoft.com/en-us/ms345578.aspx
2. https://technet.microsoft.com/en-us/library/cc197365%28v=office.12%29.aspx
public static Price TIDgetSTDCostItemPrice(ItemId _itemId,TransDate _activationDate,InventSiteId _inventSiteId) { InventDim InventDimLoc; InventItemPrice inventItemPriceLoc; InventDimLoc.clear(); InventDimLoc.InventSiteId = _inventSiteId; InventDimLoc = InventDim::findOrCreate(InventDimLoc); inventItemPriceLoc = InventItemPrice::findCurrent(_itemId,CostingVersionPriceType::Cost,InventDimLoc.inventDimId, _activationDate,_inventSiteId,InventItemCostingType::Standard); return inventItemPriceLoc.Price; }
static boolean sendEmail(str toAddress, str theSubject, str body, str fromAddress) { SysEmailParameters parameters = SysEmailParameters::find(); System.Net.Mail.SmtpClient mailClient; System.Net.Mail.MailMessage mailMessage; System.Net.Mail.MailAddress mailFrom; System.Net.Mail.MailAddress mailTo; System.Net.Mail.MailAddressCollection mailToCollection; System.Net.Mail.MailAddressCollection mailCCCollection; System.Net.Mail.AttachmentCollection mailAttachementCollection; System.Net.Mail.Attachment mailAttachment; System.Net.NetworkCredential mailCredentials; System.Exception e; List toList; ListEnumerator le; SMTPRelayServerName mailServer; SMTPPortNumber mailPortNumber; SMTPUserName mailUserName; SMTPPassword mailPassword; InteropPermission interopPermission; ; try { interopPermission = new InteropPermission(InteropKind::ComInterop); interopPermission.assert(); if (parameters.SMTPRelayServerName) { mailServer = parameters.SMTPRelayServerName; } else { mailServer = parameters.SMTPServerIPAddress; } mailPortNumber = parameters.SMTPPortNumber; mailUserName = parameters.SMTPUserName; mailPassword = SysEmailParameters::password(); mailCredentials = new System.Net.NetworkCredential(mailUserName,mailPassword); mailClient = new System.Net.Mail.SmtpClient(mailServer, mailPortNumber); mailFrom = new System.Net.Mail.MailAddress(parameters.SMTPUserName); //fromAddress); toList = strSplit(toAddress,';'); le = toList.getEnumerator(); le.moveNext(); mailTo = new System.Net.Mail.MailAddress(strLTrim(strRTrim(le.current()))); mailMessage = new System.Net.Mail.MailMessage(mailFrom, mailTo); mailToCollection = mailMessage.get_To(); while(le.moveNext()) { mailToCollection.Add(strLTrim(strRTrim(le.current()))); } mailMessage.set_From(mailFrom); mailMessage.set_ReplyTo(mailFrom); mailMessage.set_Priority(System.Net.Mail.MailPriority::High); mailMessage.set_Subject(theSubject); mailMessage.set_IsBodyHtml(true); mailMessage.set_Body(body); if(parameters.TIDUsingSSLorTSL) { mailClient.set_EnableSsl(true); mailClient.set_UseDefaultCredentials(false); mailClient.set_Credentials(mailCredentials); } else { mailClient.set_EnableSsl(false); } mailClient.Send(mailMessage); mailMessage.Dispose(); CodeAccessPermission::revertAssert(); //info("Email has been send."); } catch (Exception::CLRError) { e = ClrInterop::getLastException(); while (e) { info(e.get_Message()); e = e.get_InnerException(); } CodeAccessPermission::revertAssert(); return false; } }
source : my senior’s code