Error when fetching data on server using a function
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Im getting this error: "ErrorConditon 'Condition: current.problem_id.changes() || current.operation() == 'delete'' in business rule 'Update Problem Incident Count' on incident: INC0008111 evaluated to null; skipping business rule" when i wrap the fetch in a function in the server script. It doesnt happen on the original fetch but only when I call the server script to update the db. If i just let the script run down to the fetch without wrapping it in a function I dont have this issue.
Heres my server code:
(function() {
var gr = new GlideRecordSecure('incident');
var updateSuccessful = false;
if (input && input.action == "saveUpdate" && input.recordSysId) {
if (gr.get(input.recordSysId)) {
var records = input.records;
for (var i = 0; i < records.length; i++) {
var record = records[i];
if (record.recordId == input.recordSysId) {
gr.setValue('short_description', record.shortDescription);
updateSuccessful = gr.update() != null;
break;
}
}
}
data.updateSuccessful = updateSuccessful
data.action = null
data.recordSysId = null
return
}
function fetchData() {
data.records = [];
gr.addEncodedQuery('caller_idDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
gr.query();
while(gr.next()) {
data.records.push({
recordId: gr.getValue("sys_id"),
number: gr.getValue("number"),
shortDescription: gr.getValue("short_description"),
priority: gr.getValue("priority"),
updated: gr.getValue("sys_updated_on")
});
}
}
fetchData()
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Leejcharlto
Please try creating a new GlideRecordSecure object for the Incident table inside the if condition instead of using the object created during page load
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Is that standard procedure? Should GlideRecordSecure never be created once at the top of the function and only ever locally where needed? Thanks for the reply!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
When the page loads, the server script executes and gr is created.
Later, when the client calls the server script with parameters, the server script executes again as a new request. The previous gr object from the page-load execution is not retained.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I understand that. I just didnt think there would be an issue creating the glideRecord at the start of the script instead of creating it everywhere its needed.
