Highlighted
Respected Contributor.
Respected Contributor.
434 views

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

Jump to solution

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

0 Likes
1 Solution

Accepted Solutions
Highlighted
Trusted Contributor.
Trusted Contributor.

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

Jump to solution

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

View solution in original post

Tags (1)
4 Replies
Highlighted
Trusted Contributor.
Trusted Contributor.

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

Jump to solution

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

View solution in original post

Tags (1)
Highlighted
Respected Contributor.
Respected Contributor.

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

Jump to solution

Hi Aleks,

Thanks for the reply 🙂

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

Thanks & Regards,

Jithisha

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

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

Jump to solution

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

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

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

Jump to solution

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).

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.