- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2024 05:25 AM
In Incident form there is related list name-problem if the related list is empty I can not change the state of incident form new to inprogrees. if it is not empty then I can move the state. how I can achieve this..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2024 07:25 AM
Try below onChange Client script and script include -
onChange client script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === oldValue) {
return;
}
if (newValue == 2) {
// Call the Script Include
var ga = new GlideAjax('CheckRelatedProblems');
ga.addParam('sysparm_name', 'hasRelatedProblems');
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
ga.getXMLAnswer(function(response) {
if (response == "false") {
g_form.addErrorMessage("Cannot change the state to In Progress because there are no related Problems.");
g_form.setValue('state', oldValue); // Revert the state to its previous value
}
});
}
}
Script Include -
var CheckRelatedProblems = Class.create();
CheckRelatedProblems.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasRelatedProblems: function() { // Changed method name to match sysparm_name
var incidentId = this.getParameter('sysparm_sys_id');
var problemGR = new GlideRecord('problem');
problemGR.addQuery('parent', incidentId); // Adjusted field if needed
problemGR.query();
// Return result as "true" or "false" as a string
var result = problemGR.hasNext() ? "true" : "false";
return result;
},
type: 'CheckRelatedProblems'
});
Output -
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2024 04:03 AM
ok now I get it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2024 05:54 AM
@keshav77 ,
Is it working for you? Let me know if you require anything else.
Please mark as "Accepted Solution" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish