0 votes

Hi everyone,

I found this weird bug during a migration from 10sp2 to efficy 11.

This code, in a workflow :

dateReturn = query.fieldByName('actiBegin').AsFloat;

Return : 43201.614583333336.

As you can see, this in a valid date in delphi, and this is the date I expected :

enter image description here

But, when I try to use it in a date field, I got an error, saying that this is an invalid timestamp :

enter image description here

'622884827.-25975808' is not a valid timestamp

I had to use this trick in order to use my date :

dateReturn = Math.round(query.fieldByName('actiBegin').AsFloat*1000000)/1000000 + 0.000001;

Is there something I missed ?

In Conficy, the field is well defined and there is no "datalength" added in sys_fields.
I use the last build of Efficy 11.

Thanks,

Loïc

closed with the note: Use JS object to avoid this problem
asked in WorkFlow / Serverscript by (531 points)
closed by
Can you please copy the code of your second screen shot, we cannot see it properly ?
try {

            var CompDS = Efficy.getMasterDataset(CompCxt, 0);
            CompDS.edit();

            //Update "PREV_ACTION"
            var strAction = GetCompAction(kComp,'prev');

            if( strAction != "" ) {

                var arrAction = strAction.split(";");

                if(arrAction[0] !== ''){
                    CompDS.fieldByName('F_D_PREV_ACTI').AsFloat = arrAction[0];
                }

                CompDS.fieldByName('F_PREV_ACTI').AsInteger = arrAction[1];
                bCommit = true;
            }

            //Update "NEXT_ACTION"
            strAction = GetCompAction(kComp,'next');

            if( strAction != "" ) {
                var arrAction = strAction.split(";");

                if(arrAction[0] !== ''){
                    CompDS.fieldByName('F_D_NEXT_ACTI').AsFloat = arrAction[0];
                }
                CompDS.fieldByName('F_NEXT_ACTI').AsInteger = arrAction[1];
                bCommit = true;
            }

            //COMP$MAINTENANCE
            if( actiNature == 44 && actiDone == 1 ) { // 44 : Réparation sous contrat de maintenance
                Efficy.activateCategory(CompCxt, 'COMP$MAINTENANCE');
                var MaintDS = Efficy.getCategoryDataSet(CompCxt, 'COMP$MAINTENANCE');
                MaintDS.edit();

                var d_corrmaint = actiDS.FieldByName('D_BEGIN').AsFloat;
                MaintDS.fieldByName('F_D_PREVMAINT').AsFloat = d_corrmaint;

                cCommit = true;

            }
            if( actiNature == 41 || actiSubject == "Maintenance préventive") { // 41 : Maintenance préventive

                Efficy.activateCategory(CompCxt, 'COMP$MAINTENANCE');
                var MaintDS = Efficy.getCategoryDataSet(CompCxt, 'COMP$MAINTENANCE');
                MaintDS.edit();

                var d_prevMaint = actiDS.FieldByName('D_BEGIN').AsFloat;
                MaintDS.fieldByName('F_D_PREVMAINT').AsFloat = d_prevMaint;

                cCommit = true;
            }
            

            if( bCommit || cCommit) {

                Efficy.disableWorkflow = true;
                Efficy.commitChanges(CompCxt, false);
                Efficy.disableWorkflow = false;

            }
        }
        finally {
            Efficy.closeContext(CompCxt);
        }



-----------------------------------------

function GetCompAction(kComp,type){
    var strReturn = ";0";
    if( kComp > 0 ) {

        var sql = "select AT.K_ACTION, AT.D_BEGIN as actiBegin, AT.F_NATURE as actiNature from ACTI_COMP AC inner join ACTIONS AT on AC.K_ACTION = AT.K_ACTION where K_COMPANY = :param1";

        switch(type.toUpperCase()) {
            case 'PREV':
                sql += " and AT.DONE = 1 order by AT.D_BEGIN desc";
                break;
            case 'NEXT':
                sql += " and AT.F_NATURE in (67,68,69,70,71,72,73,74,75,76,77,78,79,80,81)"; //conserver la dernière action technique
                sql += " and AT.DONE = 0 order by AT.D_BEGIN desc";
                break;
            default:
                sql += "";
                break;
        }

        var query = Efficy.sqlQueryDataSet(sql, kComp);

        if(query && !query.isEmpty()) {
            query.first();

            var floatVal = query.fieldByName('actiBegin').AsFloat

            strReturn = Math.round(floatVal);


            var fNature = query.fieldByName("actiNature").AsString;

            if( !fNature ) fNature = 0;
            strReturn += ";" + fNature;
        }
    }

    return strReturn;
}
the bug occur when it reach :

    CompDS.fieldByName('F_D_NEXT_ACTI').AsFloat = arrAction[0];

2 Answers

+1 vote

Dear Loic,

Why didn't you use Javascript object to return the values ?

I think something like this should do the trick (I added "//Modification" comment on all my modifications)

try {

            var CompDS = Efficy.getMasterDataset(CompCxt, 0);
            CompDS.edit();

            //Update "PREV_ACTION"
            var actiObj = GetCompAction(kComp,'prev'); //Modification

            if( actiObj.dBegin > 0 ) { //Modification
                CompDS.fieldByName('F_D_PREV_ACTI').AsFloat = actiObj.dBegin; //Modification
                CompDS.fieldByName('F_PREV_ACTI').AsFloat = actiObj.Nature; //Modification
                bCommit = true;
            }

            //Update "NEXT_ACTION"
            actiObj = GetCompAction(kComp,'next'); //Modification

            if( actiObj.dBegin > 0 ) { //Modification
                CompDS.fieldByName('F_D_NEXT_ACTI').AsFloat = actiObj.dBegin; //Modification
                CompDS.fieldByName('F_NEXT_ACTI').AsFloat = actiObj.Nature; //Modification
                bCommit = true;
            }

            //COMP$MAINTENANCE
            if( actiNature == 44 && actiDone == 1 ) { // 44 : Réparation sous contrat de maintenance
                Efficy.activateCategory(CompCxt, 'COMP$MAINTENANCE');
                var MaintDS = Efficy.getCategoryDataSet(CompCxt, 'COMP$MAINTENANCE');
                MaintDS.edit();

                var d_corrmaint = actiDS.FieldByName('D_BEGIN').AsFloat;
                MaintDS.fieldByName('F_D_PREVMAINT').AsFloat = d_corrmaint;

                cCommit = true;

            }
            if( actiNature == 41 || actiSubject == "Maintenance préventive") { // 41 : Maintenance préventive

                Efficy.activateCategory(CompCxt, 'COMP$MAINTENANCE');
                var MaintDS = Efficy.getCategoryDataSet(CompCxt, 'COMP$MAINTENANCE');
                MaintDS.edit();

                var d_prevMaint = actiDS.FieldByName('D_BEGIN').AsFloat;
                MaintDS.fieldByName('F_D_PREVMAINT').AsFloat = d_prevMaint;

                cCommit = true;
            }


            if( bCommit || cCommit) {

                Efficy.disableWorkflow = true;
                Efficy.commitChanges(CompCxt, false);
                Efficy.disableWorkflow = false;

            }
        }
        finally {
            Efficy.closeContext(CompCxt);
        }



-----------------------------------------

function GetCompAction(kComp,type){
    var actiObj = {}; //Modification
    actiObj.dBegin = 0; //Modification
    actiObj.Nature = 0; //Modification

    if( kComp > 0 ) {

        var sql = "select AT.K_ACTION, AT.D_BEGIN as actiBegin, AT.F_NATURE as actiNature from ACTI_COMP AC inner join ACTIONS AT on AC.K_ACTION = AT.K_ACTION where K_COMPANY = :param1";

        switch(type.toUpperCase()) {
            case 'PREV':
                sql += " and AT.DONE = 1 order by AT.D_BEGIN desc";
                break;
            case 'NEXT':
                sql += " and AT.F_NATURE in (67,68,69,70,71,72,73,74,75,76,77,78,79,80,81)"; //conserver la dernière action technique
                sql += " and AT.DONE = 0 order by AT.D_BEGIN desc";
                break;
            default:
                sql += "";
                break;
        }

        var query = Efficy.sqlQueryDataSet(sql, kComp);

        if(query && !query.isEmpty()) {
            query.first();

            actiObj.dBegin = query.fieldByName('actiBegin').AsFloat; //Modification
            actiObj.Nature = query.fieldByName("actiNature").AsFloat; //Modification it seems that the F_NATURE is a lookup by key ... so use also a AsFloat value (if null it will return 0)

        }
    }

    return actiObj; //Modification
}

Best Regards,
Stéphane R.

answered by (1.9k points)
Hello Stéphane,

With your suggestion, I can not reproduce the bug. I suppose it is fix by your improvement, thanks a lot.

I just do the migration the project. Because it worked well on the previous version, I thought that it wasn't the problem.
0 votes

EDIT : the trick does not work in every situation.

The way I use the Math.round() is not correct and I don't know the rules of a valid timestap in Delphi

Because my client does not care about the hours and the minutes, I used a simple math.trunc(). (Math.trunc is not not supported by Efficy, but is emulated here)

With this technique, I always get the correct day.

answered by (531 points)
1,248 questions
1,518 answers
1,858 comments
328 users