Re: Max and Min value of sysmodtime in a recordset (544 Views)
Reply
Respected Contributor
brav0
Posts: 915
Registered: ‎12-07-2008
Message 1 of 9 (560 Views)
Accepted Solution

Max and Min value of sysmodtime in a recordset

Experts,

 

I have a requirement to relate a record to the newly creating incident record based on a query 

affected.item = \""+record.afftected_item+"\"" and open~=\"Closed\"" , if this query returns n records then , I need to take the oldest record in the recordset and relate it to the newly creating record...

 

Could any1 guide me in finding the max and minimum value of sysmodtime in a recordset of incidents records ?. 

 

Thank you

brav0

I am Listening..
Please use plain text.
Respected Contributor
brav0
Posts: 915
Registered: ‎12-07-2008
Message 2 of 9 (555 Views)

Re: Max and Min value of sysmodtime in a recordset

Experts,

 

As per my knowledge there is no max and min fun to find the value in a structure in SC/ SM js.

Now what I am trying to do is on a do..while loop , trying to store the sysmodtime on to a variable for each record and then comparing it with the next record.

while trying to achieve this, i am trying to store the sysmodtime value on to a variable and while compiling, its givning the below error

"

Process panel process.option in RAD display encountered error in line 1 (display,process.option)
Cannot evaluate expression (display,process.option)
Cannot evaluate expression (display,process.option)
Cannot evaluate expression (display,process.option)
Bad arg(2) oper = (display,process.option)
Cannot evaluate expression (display,process.option)
Cannot evaluate expression (display,process.option)
Script 'test_2' line 27: ERROR TypeError: myFile has no properties at char 1"

 

Below is the test script.

 

print("start of the screlate insertion script");
var myFile = new SCFile("incidents");

var rcs = myFile.doSelect("affected.item = \"ACMEpc014\" and open~=\"Closed\"");

if (rcs == RC_SUCCESS)

{

do
{
print("success");
print(myFile.incident_id);
//var myTime = new Array();
var myTime = myFile.sysmodtime;

} while(myFile.getNext()== RC_SUCCESS)

}

 

Please guide..

 

Thank you

brav0

I am Listening..
Please use plain text.
Honored Contributor
Piku
Posts: 3,942
Registered: ‎06-17-2010
Message 3 of 9 (553 Views)

Re: Max and Min value of sysmodtime in a recordset

as per : Script 'test_2' line 27: ERROR TypeError: myFile has no properties at char 1"

can you please tell what is exact there in line 27 of script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Assign Kudo, if found post useful and mark it accepted if solves the issue.
http://h30499.www3.hp.com/t5/Tips-and-Tricks/Kudos-what-where-how-and-why/m-p/5677925#U5677925
Please use plain text.
Respected Contributor
brav0
Posts: 915
Registered: ‎12-07-2008
Message 4 of 9 (544 Views)

Re: Max and Min value of sysmodtime in a recordset

 

I actually figured this out ..

I can do this by Storing the incident.id into an array and sorting the incident.id on an ascending order. The first one will be the oldest ticket.

Later I can use this interaction to relate to the incident....

 

 

I am Listening..
Please use plain text.
Respected Contributor
brav0
Posts: 915
Registered: ‎12-07-2008
Message 5 of 9 (540 Views)

Re: Max and Min value of sysmodtime in a recordset

Experts,

 

The requirement is to insert a screlation record. 
 while opening an interaction, if the new interactions affected.item is alreay raised in another interaction and it is open, then need to relate the oldest interaction into the new interaction.
This when placed in the trigger of interaction after add, it gives error, but when executed in the Script library, it works well
Below is the code for it

 

var myFile = new SCFile("incidents");
var rcs = myFile.doSelect("logical.name = \""+record.logical_name+"\" and open~=\"Closed\"");

if (rcs == RC_SUCCESS){
var i =0;
print("am here");
var myIncArray = new Array();
while (rcs == RC_SUCCESS){
print(myFile.incident_id);
myIncArray[i] = myFile.incident_id
i=i+1;
rcs = myFile.getNext();
}
print(myIncArray)
var nRc = new SCDatum();
var myflg = system.functions.rtecall("sort",nRc,myIncArray,1,0)
print("Result of sorting is \n" +myflg)
print("**sorted array is ** \n" +myIncArray)

print("starting to screlate");
//var newRecord = new SCFile()
var newRecord=system.vars.$L_new;;
print("the new record is " +newRecord);
var myFile = new SCFile("screlation");
myFile.source = newRecord.incident_id;
print("**source is **" +myFile.source);
myFile.source_active = "true";
myFile.source_filename = "incidents";
myFile.depend = myIncArray[0];
print(myIncArray[0]);
myFile.depend_filename = "incidents";
myFile.depend_active= true;
var rcS = myFile.doInsert();
if (rcS == RC_SUCCESS) {
print("record inserted");
}

}

 

ANy help is appreciated..

I am Listening..
Please use plain text.
Respected Contributor
brav0
Posts: 915
Registered: ‎12-07-2008
Message 6 of 9 (536 Views)

Re: Max and Min value of sysmodtime in a recordset

Experts,

 

In the below lines, when I execute

 

print("starting to screlate");
//var newRecord = new SCFile()
var newRecord=system.vars.$L_new;
print("the new record is " +newRecord); -------- I am getting NULL here
var myFile = new SCFile("screlation");
myFile.source = newRecord.incident_id;
print("**source is **" +myFile.source);
myFile.source_active = "true";
myFile.source_filename = "incidents";
myFile.depend = myIncArray[0];
print(myIncArray[0]);
myFile.depend_filename = "incidents";
myFile.depend_active= true;
var rcS = myFile.doInsert();
if (rcS == RC_SUCCESS) {
print("record inserted");

I am Listening..
Please use plain text.
Honored Contributor
Piku
Posts: 3,942
Registered: ‎06-17-2010
Message 7 of 9 (532 Views)

Re: Max and Min value of sysmodtime in a recordset

why are you using system.vars.$L_new
as i know in triggers file variable are as follow:

current record : record (same as $file)
save record : oldrecord (same as $file0)


hth,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Assign Kudo, if found post useful and mark it accepted if solves the issue.
http://h30499.www3.hp.com/t5/Tips-and-Tricks/Kudos-what-where-how-and-why/m-p/5677925#U5677925
Please use plain text.
Respected Contributor
brav0
Posts: 915
Registered: ‎12-07-2008
Message 8 of 9 (532 Views)

Re: Max and Min value of sysmodtime in a recordset

I realize that $L.new and $L.old doesnt work in triggers

Only record and oldrecord works.

I changed the code to below and it works..

 

var myFile = new SCFile("incidents");
var rcs = myFile.doSelect("logical.name = \""+record.logical_name+"\" and open~=\"Closed\"");

print("value of the device is \n" +record.logical_name);

if (rcs == RC_SUCCESS){
var i =0;
print("am here");
//var mymodTime = new Date()
//var myoldDate = new Date()
//var minVal = new Date();
var myIncArray = new Array();
while (rcs == RC_SUCCESS){
print(myFile.incident_id);
myIncArray[i] = myFile.incident_id
i=i+1;
rcs = myFile.getNext();
}
print(myIncArray)
var nRc = new SCDatum();
var myflg = system.functions.rtecall("sort",nRc,myIncArray,1,0)
print("Result of sorting is \n" +myflg)
print("**sorted array is ** \n" +myIncArray)
print("Current record is **" +system.vars.$L_file);

print("starting to screlate");
//var newRecord = new SCFile()
var newRecord = record;
print("the new record is " +newRecord);
// var incRec = "SD10047"
var myFile = new SCFile("screlation");
myFile.source = record.incident_id;
print("**source is **" +myFile.source);
// myFile.source = incRec;
// print(myFile.source);
myFile.source_active = "true";
myFile.source_filename = "incidents";
myFile.depend = myIncArray[0];
print(myIncArray[0]);
myFile.depend_filename = "incidents";
myFile.depend_active= true;
var rcS = myFile.doInsert();
if (rcS == RC_SUCCESS) {
print("record inserted");
}

}

I am Listening..
Please use plain text.
Honored Contributor
Piku
Posts: 3,942
Registered: ‎06-17-2010
Message 9 of 9 (526 Views)

Re: Max and Min value of sysmodtime in a recordset

Hi Brav0,

From your JS it seems that you are traversing to last of a record list and then sorting it in reverse order.And after it you are using your first record now(which was last in initially generated list).
If so you can use the ".getLast()" function to jump to last record in rcs.
use it as rcs=myFile.getLast();


This will reduce the over head of while loop and sorting of array.


hth,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Assign Kudo, if found post useful and mark it accepted if solves the issue.
http://h30499.www3.hp.com/t5/Tips-and-Tricks/Kudos-what-where-how-and-why/m-p/5677925#U5677925
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation