Service Manager / Service Center Practitioners Forum
Showing results for 
Search instead for 
Do you mean 

Trigger - URGENT

Trusted Contributor

Trigger - URGENT

Hi All,

 

the current requirement is to capture elapsed time from SLO response table to Incident.

For every Incident we have 2 SLO

Genral SLO which gets attached to all the Incident

Vendor SLO, this gets attached only when pending vendor is selected.

 

I am able to achive in getting both the elapsed time to Incident using trigger

Now customer wants sum of both the elapsed time, like a+b=c

Example:

SLO1 Elapsed time: 01:00:00

SLO2 Elapsed time:04:00:00

Total.time= 05:00:00

 

Elapsed time is captured once the ticket is closed, in FC I wrote condition but calcution does not happen when I close the Incident, I have to click on save or ok once again to achive but customer is not agreeing for that.

 

CAn you please help me with the script.

I have written 2 triggers to capture those fields, can you help me in making that as 1 trigger which can capture both the fields and sum them

 

Please find the trigger - 1

 

if (record.problem_status=="Closed" && record.actual_resolved_dur==null)
{
print("Enter 1")
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"259\" or slo.id=\"434\")")

print("slo.id")
if(findsloResponse==RC_SUCCESS)
{
record.actual_resolved_dur=fsloResponse.total_time
print("fsloResponse.actual_resolved_dur")

}
}

 

trigger - 2

 

if (record.problem_status=="Closed" && record.actual_res_dur_vend==null)
{
print("Enter 1")
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"179\" or slo.id=\"434\")")

print("slo.id")
if(findsloResponse==RC_SUCCESS)
{
record.actual_res_dur_vend=fsloResponse.total_time
print("fsloResponse.actual_res_dur_vend")

}
}

14 REPLIES
Frequent Advisor

Re: Trigger - URGENT

Hi ,

Could you please kindly let us know details about your setting ( format control, script, ....)? With the capture image that would be great.

Regards,
Quan
Honored Contributor Honored Contributor

Re: Trigger - URGENT

Hi,

These all elapse time fields are seems to be customized one.
So to get the combination of bot elapse time you should code for same after above code.

Why using two triggers, use one only and add all the code to same.
In last add the code to sum to add bot fields.


hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.
Trusted Contributor

Re: Trigger - URGENT

Hi,

 

Thanks for your help

 

can you please help me with the script on make these 2 tiggers as one and sum of both the elapsed time.

 

Regards,

Madhan

Honored Contributor Honored Contributor

Re: Trigger - URGENT

Hi,

You have to just copy and paste the second trigger code, to next line where first trigger codes ends.

And in each code, add expressions before ending the inner 'if',

First trigger code :
vars.$slo1=fsloResponse.total_time

Second trigger code:
vars.$slo2=fsloResponse.total_time

Then in last lines of total after appending each code put expressions,
record.elapse_time= vars.$slo1 + vars.$slo2
vars.$slo1 = null ;
vars.$slo2 = null ;

hope it is clear.

hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.
Trusted Contributor

Re: Trigger - URGENT

Hi Pike,

 

I tried below script also tried what you have suggested but getting below error, I have commented those lines, tried with that as well still no luck

 

Update cancelled by trigger (apm.save.problem,update.go)
file:(probsummary) key:(number=IM10142) (apm.save.problem,update.go)
Script <no name> line 34: ERROR ReferenceError: Print is not defined at char 1

 

if (record.problem_status=="Pending Change" && record.actual_resolved_dur==null)
{
//print("Enter 1")
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"179\" or slo.id=\"434\")")

//print("slo.id")
if(findsloResponse==RC_SUCCESS)
{
record.actual_resolved_dur=fsloResponse.total_time
print("fsloResponse.actual_resolved_dur")

}
}

if (record.problem_status=="Pending Change" && record.actual_res_dur_vend==null)
{
//print("Enter 1")
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"218\" or slo.id=\"434\")")

//print("slo.id")
if(findsloResponse==RC_SUCCESS)
{
record.actual_res_dur_vend=fsloResponse.total_time
print("fsloResponse.actual_res_dur_vend")

}
}
//vars.$slo1=record.actual_resolved_dur
//vars.$slo2=record.actual_res_dur_vend
//var slo1=record.actual_resolved_dur
//var slo2=record.actual_res_dur_vend
Print("Entering")
{
Print("entering- 1")
//record.all_resolved_time= var slo1 + var slo2
record.all_resolved_time= record.actual_resolved_dur+record.actual_res_dur_vend
}

Trusted Contributor

Re: Trigger - URGENT

this is the error message I am getting.

 

Update cancelled by trigger (apm.save.problem,update.go)
file:(probsummary) key:(number=IM10142) (apm.save.problem,update.go)
Script <no name> line 38: ERROR Cannot store a string into an object of type time at char 1

Honored Contributor Honored Contributor

Re: Trigger - URGENT

Hi,

It seems that datatype of all three below fields are different,
actual_resolved_dur
actual_res_dur_vend
all_resolved_time

Did you define first two as string type in dbdict ? Then better you should make them date type for future reporting and comparison also.
You convert the string to JS date type and then store in ‘all_resolved_time’ field.


Ensure that all have same data type as datetime.

Hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.
Honored Contributor

Re: Trigger - URGENT

Is line record.all_resolved_time= record.actual_resolved_dur+record.actual_res_dur_vend on line 38 ?

If it is, the sum of the duration may be in String format and record.all_resolved_time is in Time format. You could try the date.parse() function, it may convert it to Date format successfully for you.

Trusted Contributor

Re: Trigger - URGENT

Hi ,

 

All three 3 fields are time/date type.

 

actual_resolved_dur
actual_res_dur_vend
all_resolved_time

 

Would you please help me as how to change it.

 

regards,

Madhan

Honored Contributor Honored Contributor

Re: Trigger - URGENT

Hi Madhan,


Just checked you are having querying with two slo id with 'or' condition so in case of multiple records it will select one record only.
Hence better remove one sloi ds from each query.
It is possible while addin one of ‘actual_res_dur’ is null.

Also paste snap shot of dbdict where these there fields are defined.

Print all three values in js and post snap shot.

hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.
Trusted Contributor

Re: Trigger - URGENT

Tried with the following script but still getting error

attached the snapshot of dbdict - probsummary

 

if (record.problem_status=="Pending Change" && record.actual_resolved_dur==null)
{
//print("Enter 1")
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"179\" or slo.id=\"434\")")

//print("slo.id")
if(findsloResponse==RC_SUCCESS)
{
record.actual_resolved_dur=fsloResponse.total_time
print("fsloResponse.actual_resolved_dur")

}
}

if (record.problem_status=="Pending Change" && record.actual_res_dur_vend==null)
{
//print("Enter 1")
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"218\" or slo.id=\"434\")")

//print("slo.id")
if(findsloResponse==RC_SUCCESS)
{
record.actual_res_dur_vend=fsloResponse.total_time
print("fsloResponse.actual_res_dur_vend")

}
}
//vars.$slo1=record.actual_resolved_dur
//vars.$slo2=record.actual_res_dur_vend
var slo1=record.actual_resolved_dur.getTime()
var slo2=record.actual_res_dur_vend.getTime()
var one_day=1000*60*60*24
//Print("Entering")
{
//Print("entering- 1")
var slo0 = slo1 + slo2
record.all_resolved_time = slo0
//var total=date.parse(record.all_resolved_time);
//date.parse(record.all_resolved_time)=date.parse(record.actual_resolved_dur)+date.parse(record.actual_res_dur_vend)
//record.all_resolved_time= record.actual_resolved_dur+record.actual_res_dur_vend
}

Honored Contributor Honored Contributor

Re: Trigger - URGENT

You are having querying with two slo id with 'or' condition so in case of multiple records it will select one record only.
Hence better remove one sloi ds from each query.
It is possible while addin one of ‘actual_res_dur’ is null.

Print all three values in js and post error snap shot.

hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.
Trusted Contributor

Re: Trigger - URGENT

Hi Piku,

 

at any point only one slo will get selected, based on the condition.

 

as I said when Inicdent is opned then genral SLO gets selected and once the status is selected for pending vendor then another slo gets selected.

while closing the Incident we want to sum both the  SLO duriation.

 

Regards,

Madhan

Honored Contributor Honored Contributor

Re: Trigger - URGENT

Hi,

Ok, now when closing only you need the sum of time.

Then you have to add the ‘if’ statement while calculating final time and remove all other if condition since you have to anyway put the sum by fetching value form respective sloresponse record.
Don’t Know where and when you are populating the values. But to calculate the sum time, both slo time must be there in record or sloresponse table.

if (record.problem_status=="Closed”)
{ // start of close calc – first if
var fsloResponse=new SCFile("sloresponse")
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"179\" or slo.id=\"434\")")
if(findsloResponse==RC_SUCCESS)
{
record.actual_resolved_dur=fsloResponse.total_time
var $slo1 = fsloResponse.total_time
print("fsloResponse.actual_resolved_dur")

}
var findsloResponse=fsloResponse.doSelect("foreign.key=\""+record.number+"\" and (slo.id=\"218\" or slo.id=\"434\")")
if(findsloResponse==RC_SUCCESS)
{
record.actual_res_dur_vend=fsloResponse.total_time
var $slo2 = fsloResponse.total_time
print("fsloResponse.actual_res_dur_vend")
}

record.all_resolved_time= vars.$slo1 + vars.$slo2

} // end of first if


Hth,
____________________________________
Assign Kudo, if found post useful and mark it accepted if solves the issue.