- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 01:33 AM
Hi All,
I have a requirement change request have any active change tasks are presented in related list tab, need to display info message on Change form.
I have written the below scripts, when checked using logs it is getting always return false.
Can some one help me on this.
Script Inlcude:
// Display info message
checkimpTask: function(parentChg) {
var answer;
var chgTask = new GlideRecord("change_task");
chgTask.addQuery("change_request", parentChg);
chgTask.addQuery("change_task_type", "planning");
chgTask.addQuery("active", "true");
chgTask.query();
if (chgTask.next()) {
answer = 'true';
}
return answer;
},
Client script:
Onload
table: change
function onLoad() {
//Type appropriate comment here, and begin script below
var cTask = new GlideAjax('StdChangeTaskUtils');
cTask.addParam('sysparm_name', checkimpTask);
cTask.getXML(chgTask);
}
function chgTask(response) {
var Validation = response.responseXML.documentElement.getAttribute('answer');
if (Validation == 'true') {
g_form.showFieldMsg('Display comments');
}
}
Thanks,
Praveen D.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 01:50 AM
@praveen47 Please update your script include as follows.
// Display info message
checkimpTask: function() {
var answer;
var parentChange = this.getParameter("sysparm_parent_change");
var chgTask = new GlideRecord("change_task");
chgTask.addQuery("change_request", parentChange);
chgTask.addQuery("change_task_type", "planning");
chgTask.addQuery("active", "true");
chgTask.query();
if (chgTask.next()) {
answer = 'true';
}
return answer;
},
Make sure that the script include has Client Callable checkbox checked.
Update the client script as follows.
function onLoad() {
//Type appropriate comment here, and begin script below
var cTask = new GlideAjax('StdChangeTaskUtils');
cTask.addParam('sysparm_name', 'checkimpTask');
cTask.addParam('sysparm_parent_change',g_form.getUniqueValue());
cTask.getXML(chgTask);
}
function chgTask(response) {
var Validation = response.responseXML.documentElement.getAttribute('answer');
if (Validation == 'true') {
g_form.showFieldMsg('Display comments');
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 01:52 AM
you did not send the Parent Change sys_id in OnLoad Client script, add the sys_id in parameter in Glide Ajax and retrieve the parameter in Client callable script Include
Script Include:
// Display info message
checkimpTask: function() {
var parentChg = this.getParameter('sysparm_parentChange');
var answer;
var chgTask = new GlideRecord("change_task");
chgTask.addQuery("change_request", parentChg);
chgTask.addQuery("change_task_type", "planning");
chgTask.addQuery("active", "true");
chgTask.query();
if (chgTask.next()) {
answer = 'true';
}
return answer;
},
Client script:
Onload
table: change
function onLoad() {
//Type appropriate comment here, and begin script below
var cTask = new GlideAjax('StdChangeTaskUtils');
cTask.addParam('sysparm_name', checkimpTask);
cTask.addParam('sysparm_parentChange', g_form.getUniqueValue());
cTask.getXML(chgTask);
}
function chgTask(response) {
var Validation = response.responseXML.documentElement.getAttribute('answer');
if (Validation == 'true') {
g_form.showFieldMsg('Display comments');
}
}
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 01:55 AM - edited 10-11-2023 02:32 AM
HI @praveen47 ,
Use below script it will work
//Create new script include and make client callable true checkbox and paste below code
checkimpTask: function() {
var answer = '';
var parentChg=this.getParameter('sysparm_parent_chg');
var chgTask = new GlideRecord("change_task");
chgTask.addQuery("change_request", parentChg);
chgTask.addQuery("change_task_type", "planning");
chgTask.addQuery("active", "true");
chgTask.query();
if (chgTask.next()) {
answer = 'true';
}
return answer;
},
});
function onLoad() {
var parentChange = g_form.getValue('sys_id'); // parent change record's sys_id
var cTask = new GlideAjax('StdChangeTaskUtils');
cTask.addParam('sysparm_name', 'checkimpTask');
cTask.addParam('sysparm_parent_chg', parentChange);
cTask.getXML(checkChangeTasks);
}
function checkChangeTasks(response) {
var validation = response.responseXML.documentElement.getAttribute('answer');
if (validation === 'true') {
g_form.addInfoMessage('Active change tasks are present in the related list.');
}
}
Please mark it as helpful and solution proposed if it works for you.
Thanks,
Anand