Display Completed Status when all child tasks are completed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:19 AM
Hi All,
I have created 2 tables x_ggisu_projects_t_projects and x_ggisu_projects_t_child_projects.
The x_ggisu_projects_t_child_projects table is added as a related list under x_ggisu_projects_t_projects.
In x_ggisu_projects_t_child_projects table the field prefix.number has same value as number field in x_ggisu_projects_t_projects.
I want the completed status to be available in x_ggisu_projects_t_projects table form only when all records in x_ggisu_projects_t_child_projects with prefix.number same as number in x_ggisu_projects_t_projects are completed.
I have created below Script Include and Client Script for same. It is hiding the completed status in parent form however not displaying the completed status once the child tasks are completed.
Script Include
var ProjectUtils = Class.create();
ProjectUtils.prototype = {
initialize: function() {},
areAllChildProjectsClosed: function(parentNumber) {
var childProjectGR = new GlideRecord('x_ggisu_projects_t_child_projects');
childProjectGR.addQuery('prefix.number', parentNumber); // Match the child projects using prefix.number
childProjectGR.addQuery('status', '!=', 'completed'); // Check if any child project is not 'completed'
childProjectGR.query();
return !childProjectGR.hasNext(); // Returns true if all child projects are 'completed'
},
type: 'ProjectUtils'
};
Client Script
function onLoad() {
var projectNumber = g_form.getValue('number'); // Get the project number from the parent form
// Call the Script Include to check if all child projects are closed
var ga = new GlideAjax('ProjectUtils');
ga.addParam('sysparm_name', 'areAllChildProjectsClosed');
ga.addParam('sysparm_parentNumber', projectNumber);
ga.getXMLAnswer(function(response) {
var allCompleted = response === 'true';
console.log("All child projects closed? " + allCompleted); // Log to verify response
// If all child projects are closed, enable the "Completed" option
if (allCompleted) {
g_form.addOption('status', 'completed', 'Completed'); // Enable 'Completed' option if it's missing
} else {
g_form.removeOption('status', 'completed'); // Otherwise, remove the option
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:31 AM
Hello @Gunashekar
Could you please use the below script include client script code.
Script include:
var ProjectUtils = Class.create();
ProjectUtils.prototype = {
initialize: function() {},
areAllChildProjectsClosed: function(parentNumber) {
var parentNumber = this.getParameter("sysparm_parentNumber");
var childProjectGR = new GlideRecord('x_ggisu_projects_t_child_projects');
childProjectGR.addQuery('prefix.number', parentNumber); // Match the child projects using prefix.number
childProjectGR.addQuery('status', '!=', 'completed'); // Check if any child project is not 'completed'
childProjectGR.query();
while(childProjectGR.next()){
return !childProjectGR.hasNext(); // Returns true if all child projects are 'completed'
},
type: 'ProjectUtils'
};
Client Script:
Client script:
function onLoad() {
var projectNumber = g_form.getValue('number'); // Get the project number from the parent form
// Call the Script Include to check if all child projects are closed
var ga = new GlideAjax('ProjectUtils');
ga.addParam('sysparm_name', 'areAllChildProjectsClosed');
ga.addParam('sysparm_parentNumber', projectNumber);
ga.getXML(callback);
function callback(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
// try to put your required conditions here.
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:54 AM
The Script include you provided has errors so i modified it as below and used the client script as is however now the completed status is not hiding.
Script Include
var ProjectUtils = Class.create();
ProjectUtils.prototype = {
initialize: function() {},
areAllChildProjectsClosed: function(parentNumber) {
var parentNumber = this.getParameter("sysparm_parentNumber");
var childProjectGR = new GlideRecord('x_ggisu_projects_t_child_projects');
childProjectGR.addQuery('prefix.number', parentNumber); // Match the child projects using prefix.number
childProjectGR.addQuery('status', '!=', 'completed'); // Check if any child project is not 'completed'
childProjectGR.query();
// If there are any child records that are not completed, return false
if (childProjectGR.hasNext()) {
return false;
}
// If all child projects are completed, return true
return true;
},
type: 'ProjectUtils'
};
Client script
function onLoad() {
var projectNumber = g_form.getValue('number'); // Get the project number from the parent form
// Call the Script Include to check if all child projects are closed
var ga = new GlideAjax('ProjectUtils');
ga.addParam('sysparm_name', 'areAllChildProjectsClosed');
ga.addParam('sysparm_parentNumber', projectNumber);
ga.getXML(callback);
function callback(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
// try to put your required conditions here.
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 02:58 AM
Hello @Gunashekar ,
Could you please share the exact ask what you want to do?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 03:34 AM
This is the parent table below, the status completed should be visible only when the child projects attached to it are completed.
Below are the child tasks attached in related list. Table: x_ggisu_projects_t_child_projects.
When all the child tasks in this related list is completed then the completed option in parent form should be visible.
The prefix.number in child table will have same value as in number in parent table.