Thursday, July 18, 2013

Debug C# from code editor

1. Create a Class library project,
2. Add to AOT
3. Deploy to AOS
4. Create a client class

http://msdn.microsoft.com/en-us/library/hh129886.aspx

Update to Scheduling and Resource Assignment

           ttsBegin;
            psaActivitySetup = PSAActivitySetup::findActivityNumber(myActivityNumber);
            while select forUpdate psaActivitySetup
                    where PSAActivitySetup.ActivityNumber == myActivityNumber
            {
                psaActivitySetup.PSASchedStart = _startDate;
                psaActivitySetup.PSASchedEnd = dateMthFwd(_startDate, 1);
                psaActivitySetup.update();  
            }
            ttsCommit;

Wednesday, July 17, 2013

DateTime

    UTCdatetime startDate;
   
    startDate= DateTimeUtil::newDateTime(systemDateGet()+1,timenow());
    info(strFmt("%1", startDate));

   UTCdatetime datetimeTo;   
   datetimeTo = DateTimeUtil::addDays(_startDate,1);

    activities.ActivityNumber = smmParameters::getNumber(smmNumbSeqUsed::Activity);
                activities.Purpose =  _activityNum;
                activities.ResponsibleWorker = _worker;
                activities.StartDateTime = _startDate;
                activities.EndDateTime = datetimeTo;
                activities.insert();

Thursday, July 11, 2013

(Sub)Project

static void SR_CreateProjects_subProjects(Args _args)
{
ProjInvoiceTable projInvoiceTable;
ProjTableType projTableType;
NumberSeq projNumberSeq;
ProjId projIdLastSon, projectId;
ProjTable projTable;
ProjId projMask;
Integer sonNum;
ProjType _projType = ProjType::TimeMaterial;
ProjGroupId _projGroupId = ‘TM1′;
ProjName _projName = “Construction – Prj”;
ProjInvoiceProjId _projInvoiceProjId = ’100104′;
ProjParentId _projParentId = ’121′; // define parent project here
NumberSequenceFormat _numberSequenceMask;
ProjLinePropertyId _projInvoiceStatusId;
;
if (_projParentId)
{
projTable.type().initFromParent(_projParentId);
projIdLastSon = ProjTable::projIdLastSon(projTable.ParentId);
if (projIdLastSon)
{
projMask = substr(projIdLastSon, strlen(projTable.ParentId) + 1, (strlen(projIdLastSon) – strlen(projTable.ParentId) + 1));
sonNum = ProjTable::numRemTemplate(projMask, ProjTable::find(projTable.ParentId).Format);
}
projTable.ProjId = projTable.ParentId + NumberSeq::numInsertFormat(sonNum + 1, ProjTable::find(projTable.ParentId).Format);
}
else
{
projNumberSeq = NumberSeq::newGetNum(ProjParameters::numRefProjId(), true);
if (projNumberSeq)
{
projTable.ProjId = projNumberSeq.num();
}
}
projectId = projTable.ProjId;
projTable.Type = _projType;
projTable.ProjGroupId = _projGroupId;
projTable.Name = _projName;
projTableType = projTable.type();
projTableType.initProjTable();
projTable.ProjInvoiceProjId = _projInvoiceProjId;
projInvoiceTable = ProjInvoiceTable::find(_projInvoiceProjId);
projTable.CustAccount = projInvoiceTable.InvoiceAccount;
projTable.initFromInvoice(projInvoiceTable);
projTable.Format = _numberSequenceMask;
projTable.CheckBudget = ProjGroup::find(_projGroupId).CheckBudget;
if (_projInvoiceStatusId)
{
ProjLinePropertySetup::updateLinePropertyProj(projTable.ProjId, _projInvoiceStatusId, TableGroupAll::Table, true);
}
projTable.initFromCustTable(CustTable::find(projTable.CustAccount));
if (ProjTable::exist(projTable.ProjId))
{
// Project already exists.
throw error(“@SYS56494″);
}
if (!projTableType.validateWrite())
throw error (“Validations failed”);
projTable.insert();
if (projNumberSeq)
{
projNumberSeq.used();
}
else
{
projTable.clear();
if (projNumberSeq)
{
projNumberSeq.abort();
}
}
info (strfmt(‘Project %1 successfully created ‘, projectId));
}

Tuesday, July 9, 2013

Calculate Code Execution Time

static void GetExecutionTime(Args _args)
{
    int start;
    int end;
    int i;
    start = WinAPI::getTickCount();
    for (i = i; i <= 1; i++)
    {
        sleep(1000); // pause for 1000 milliseconds
    }
    end = WinAPI::getTickCount();
    info(strFmt("%1", end - start));
}

Saturday, July 6, 2013

Store Dimension Attribute Value

static void XXXX(Args _args)
{
    DimensionAttribute dimAttr;
    DimensionAttributeValue dimAttrValue;
    Name dimName;
    Name dimValue;
    Common                          common;
    DictTable                       dictTable;
    Map dimSpec;
    dimName = "Department";
    dimValue = "025";
   
     dimSpec =
        DimensionDefaultingEngine::createEmptyDimensionSpecifiers();
   
    dimAttr = DimensionAttribute::findByName(dimName);
   
    dictTable = new DictTable(dimAttr.BackingEntityType);
    common = dictTable.makeRecord();
  
    select firstonly common where common.(dimAttr.ValueAttribute) == dimValue;
    if (common)
    {
        dimAttrValue = DimensionAttributeValue::findByDimensionAttributeAndEntityInst(
            dimAttr.RecId, common.(dimAttr.KeyAttribute),
            false, false);
       
        info(strFmt("%1", common.(dimAttr.ValueAttribute)));
    }
   
}

Find or Create Attribute Value
    select firstonly
            dimensionAttributeValue
        where
            dimensionAttributeValue.DimensionAttribute == _dimensionAttribute
            && dimensionAttributeValue.EntityInstance == _entityInstance
            && dimensionAttributeValue.IsDeleted == false;
    // Create value if specified and not currently existing
    if (!dimensionAttributeValue && _createIfNecessary)
    {
        ttsbegin;
        dimensionAttributeValue.DimensionAttribute = _dimensionAttribute;
        dimensionAttributeValue.EntityInstance = _entityInstance;
        dimensionAttributeValue.insert();
        dimensionAttributeValue.selectForUpdate(_forUpdate);
        ttscommit;
    }

Wednesday, July 3, 2013

Periodic Journal

Create a Journal name, with journal type as "Periodic", such as RentExp. optional with an offset account.

From General Ledger, Periodic, Journals, Periodic Journals, create a new periodic journal.
during creation, select journal name: RentExp created on step1.
From "Lines", enter line info.

From General Ledger, Journals, General Journals, create a new GJ. Pick up name as: GerJrn, go to "Lines", From Periodic Journal, Retrieve Journal. Then "Post".