Hi,
Assuming that pdmDownTime calculates the different between Outage End Date and Outage Start Date, you can use the following steps to implement a field which captures this information. Props to Gutis for providing me with this spel a while I was still learning.
1. Open WSP and navigate to CR object
2. Add column to capture outage (Input the Name, Field Type, and Display name. All other options can be ignored)
2.1 Name: zOutageDuration
2.2 Field Type: Duration
2.3 Display Name: Total Outage Time
3. Press Save and then Save and Publish
4. Create a spel file with the following contents and place in nx_root/site/mods/magic.
cr::zCalculateOutage(...)
{
string method;
method ="cr::zCalculateOutage";
logf(MILESTONE, "%s started", method);
if (!is_empty(outage_start_time) && !is_empty(outage_end_time))
{
duration outage;
outage=outage_end_time-outage_start_time;
uuid who;
send_wait(0,top_object(), "call_attr", "cnt", "current_user_id");
who=msg[0];
send_wait(0, top_object(), "call_attr", "api", "update_object_super", who, persistent_id, 0, "zOutageDuration", outage);
}
if (is_empty(outage_start_time) && !is_empty(outage_end_time))
{
set_error(1);
set_return_data("Please provide Outage start time");
logf(MILESTONE, "%s ended", method);
return;
}
logf(MILESTONE, "%s ended", method);
}
5. Create a .mod file with the following contents and place in nx_root/site/mods/magic
MODIFY cr POST_VALIDATE zCalculateOutage() 10000 FILTER(outage_start_time{} || outage_end_time {});
6. Run pdm_publish on background or primary server to add column to db
7. Perform rolling maintenance to push change to app/secondary servers
8. Add the Outage Duration field to the incident form via WSP
<PDM_MACRO name=dtlReadonly hdr="Outage Duration" attr=zOutageDuration>
9. Test