Can't set a duration value in business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 01:16 PM
Not sure why this is being difficult.
There is a duration field u_estimated_effort on my task form. All I want to do is add time to this and have that time update to a similar field on the Case table.
The duration field isn't being updated on the case so I suspect the formatting is incorrect but when I update the short description it looks like: 19312 21:11:01
Is there something else I need to do in order to put this number back into my Case record so it updates the duration field correctly?
var duration = new GlideDuration(current.u_estimated_duration).getDurationValue();
var cs = new GlideRecord('sn_customerservice_case');
cs.addQuery('sys_id', current.u_case);
cs.query();
if (cs.next()) {
cs.short_description = duration;
cs.u_estimated_effort.setDateNumericValue(duration);
// also tried cs.u_estimated_effort = duration;
cs.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 04:01 PM
If u_estimated_duration is a duration type field, then try this:
var duration = current.u_estimated_duration.dateNumericValue();
var cs = new GlideRecord('sn_customerservice_case');
cs.addQuery('sys_id', current.u_case);
cs.query();
if (cs.next()) {
cs.short_description = duration;
cs.u_estimated_effort.setDateNumericValue(duration);
cs.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 05:28 AM
Thanks Brad,
The line of code before is part of my original post and this isn't setting the estimated effort field with any data and I still believe it's because the data isn't what the field is looking for. I double checked the name of the field dozens of times so the u_estimated_effort is correct and we are updating the correct Case's short description, but the duration field isn't taking any data I give it.
Note: There are no custom SLAs on this field and I can write to it (and edit it directly just fine).
cs.u_estimated_effort.setDateNumericValue(duration);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 06:25 AM
I can't tell from your response if you tried my script. The difference is mine works because I'm setting the script variable named 'duration' to a value that a duration type field is expecting when using setDateNumericValue. If the display value of a duration field shows 1 Day, 2 Hours, 3 Minutes, and 4 seconds the dateNumericValue is 93784000, so getting this value from one Duration type field, and setting it on another Duration type field is what you need to do as opposed to getDurationValue and setDateNumericValue.