- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 09:30 AM
Hi,
On Indicator Task form I have to set result = Passed when state changes and if attachments are present.
I created a client script on sn_grc_indicator_task table and a script include but I cant understand why it doesn't work. Somebody helps me?
I try to create client script and script include in GRC: Profile and Global scopes but nothing changed.
client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var targetType = g_scratchpad.target_type;
if (targetType != 'percentage' && targetType != 'count') {
var ga = new GlideAjax('Count_attachment');
ga.addParam('sysparm_name', 'getRowCount');
ga.addParam('table_name', g_form.getTableName());
ga.addParam('table_sys_id', g_form.getUniqueValue());
ga.getXML(updateResult);
function updateResult(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
jslog('answer' + answer); // answer is null
if (answer) {
var returneddata = answer.evalJSON(true);
var rowcount = returneddata.rowcount;
jslog('rowcount '+rowcount);
if(rowcount >0)
g_form.setValue('result', 'passed');
} else {
g_form.setValue('result', 'failed');
}
}
}
}
script include
name: Count_attachment
client callable: True
script:
var Count_attachment = Class.create();
Count_attachment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRowCount: function() {
var rowcount = 0;
var table_name = this.getParameter('table_name');
var table_sys_id = this.getParameter('table_sys_id');
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name", table_name);
attachment.addQuery("table_sys_id", table_sys_id);
attachment.query();
while (attachment.next()) {
rowcount++;
}
var results = {
"rowcount": rowcount
};
return json.encode(results);
},
//type: 'Count_attachment'
});
Solved! Go to Solution.
- Labels:
-
Integrated Risk Management (IRM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 09:45 AM
Hi
in your Script Include there is an error at the end. Instead of
return json.encode(results);
write
return JSON.stringify(results);
In case there are more errors, I recommend using my GlideAjax Test Client
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 09:45 AM
Hi
in your Script Include there is an error at the end. Instead of
return json.encode(results);
write
return JSON.stringify(results);
In case there are more errors, I recommend using my GlideAjax Test Client
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 10:53 AM
Hi, I don't think you need a client script and ajax to achieve that. you can simply create a business rule that runs on state changes and a GlideAggrergate attachment table to see whether your indicator has attachment
var IndGA = new GlideAggregate('sys_attachement');
IndGA.addEncodedQuery('table_name=sn_grc_indicator_task^table_sys_id=' + current.sys_id);
IndGA.addAggregate('COUNT');
IndGA.query();
var IndAttach = 0;
if (IndGA.next())
IndAttach = count.getAggregate('COUNT');
if (IndAttach > 0) {
current.result ='pass';
}
Please mark my answer as ✅ Correct / Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 01:03 AM
Hi Ahmed,
in my case I do not have to set value in the table, but only in the form in order to permit users to change the value.
Thank you for your contribution!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2022 01:35 AM
that makes sense if you want to do it on the client-side.