How to insert value into NEGDATESTAMP field in activity table through Script Library

Hi Experts,

My requirement is to update activity log while importing data to SM. For the same I have written a script which will be invoked from javascript of FC .

Below is the script to insert values to activity table.

function CdaxOpenNew(openTime,number,briefDescription,assignment) {

var tbActivity = new SCFile("activity");

tbActivity.datestamp=openTime;

tbActivity.number=number;

tbActivity.type="Open";

tbActivity.operator="falcon_super"

tbActivity.description[0]=briefDescription;

tbActivity.negdatestamp=system.functions.parse_evaluate("'12/31/2199 17:00:00' - openTime ", 1);

rc =tbActivity.doInsert();

}

Values are getting inserted for all the fields except negdatestamp.

If I use the below code, value will get inserted in negdatestamp. But actually, I want the result of '12/31/2199 17:00:00' – openTime to get inserted into negdatestamp.

tbActivity.negdatestamp=system.functions.parse_evaluate("'12/31/2199 17:00:00' – tod() ", 1);

tbActivity.negdatestamp=system.functions.parse_evaluate("'12/31/2199 17:00:00' - '01/22/2009 17:00:00'", 1);

 

Could you please help me to insert the correct value to negdatestamp field.

Thanks & Regards,

Jithisha

Top Replies

  • Verified Answer

    Try something like this JavaScript code.

    I change it from source topic and use it without "offset"  and all works fine:

    function getNegDateSMA(dateTime)
    {
    	var open = new Date(dateTime);
    	//var future = new Date(2200,1,1);//original future date value
    	var future = new Date(2199,11,31,8);//your value for future date
    	var delta = future - open;
    	var days = String(parseInt(delta/86400000));
    	var hours =String(parseInt((delta - (days*86400000))/3600000));
    	var minutes =String(parseInt((delta - (days*86400000) - (hours*3600000))/60000));
    	var seconds =String(parseInt((delta - (days*86400000) - (hours*3600000) - (minutes*60000) )/1000));
    	var negdatestamp = new XMLDate( "P" days "DT" hours "H" minutes "M" seconds "S");
    	negdatestamp=negdatestamp.getDatum();
    	return negdatestamp;
    }

    Create this function in ScriptLibrary and just invoke it in your "CdaxOpenNew" function.

    In FormatControl in JavaScript section this function returns value like [C object SCDatum] - 66080 19:14:50

  • Hi Aleks,

    Thanks for the reply :)

    After adding getNegDateSMA(dateTime) method, am able to insert value to negdatestamp field.

    Thanks & Regards,

    Jithisha

     

  • Hi Aleks,

    Today while testing I found one issue. I tested by passing value 2019-01-31 10:22:00.000 to getNegDateSMA(), expected result is '4180-11-30 05:38:00.000' but I got '4180-12-30 05:38:00.000'. Here I could see difference in month.

    Below is the function which I have used inside my script library.

    function getNegDateSMA(dateTime)

    {

    var open = new Date(dateTime);

    var future = new Date(2199,12,31,08);

    var delta = future - open;

    var days = String(parseInt(delta/86400000));

    var hours =String(parseInt((delta - (days*86400000))/3600000));

    var minutes =String(parseInt((delta - (days*86400000) - (hours*3600000))/60000));

    var seconds =String(parseInt((delta - (days*86400000) - (hours*3600000) - (minutes*60000) )/1000));

    var negdatestamp = new XMLDate( "P" days "DT" hours "H" minutes "M" seconds "S");

    negdatestamp=negdatestamp.getDatum();

    return negdatestamp;

    }

     

    Screen shot of Activity table:

    TimeDiff.PNG

     Please suggest a way to resolve this issue.

    Thanks & Regards,

    Jithisha

  • Hi Jithisha,

    The second row in your script should be

    var future = new Date(2199,11,31,8);

    Because in JavaScript months count from 0 to 11  (we pass 11 for December).