SPModal receive undefined values from child widget
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 04:22 AM
Hi,
I have a problem getting the value from the child widget to parent and putting it in the comment.
Parent Widget:
Body:
<div>
<div class="dropdown" id="child-case-tabs" ng-if="data.showActions">
<button type="button" id="actions-button" class="btn btn-default dropdown-toggle action-btn" data-toggle="dropdown" style="width : 100%" aria-haspopup="true" ng-init="setFocusOnActionButtons()">
${Actions}
<span class="fa fa-caret-down"></span>
</button>
<ul class="dropdown-menu pull-right" id="actionList">
<li ng-if="data.canResolve">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();resolveIncident()">${Resolve}</a>
</li>
<li ng-if="data.canReopen">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();reopenIncident()">${Reopen}</a>
</li>
<li ng-if="data.canEscalate">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();escalateIncident()">${Escalate}</a>
</li>
<li ng-if="data.canClose">
<a href="javascript:void(0)" ng-click="$event.stopPropagation();closeIncident()">${Close}</a>
</li>
</ul>
</div>
</div>
Server:
(function() {
var incidentGr = new GlideRecord('incident');
var incidentSysId = options.sys_id;
if (!incidentSysId && $sp.getParameter('table') == 'incident')
incidentSysId = $sp.getParameter('sys_id');
if (!incidentSysId && $sp.getParameter('table') == 'universal_request') {
var urGr = new GlideRecord('universal_request');
urGr.get($sp.getParameter('sys_id'));
incidentSysId = urGr.primary_task + "";
}
/* Actions - Start */
// if (input && input.action == 'resolveIncident' && incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "write")) {
// incidentGr.incident_state = global.IncidentState.RESOLVED;
// incidentGr.state = global.IncidentState.RESOLVED;
// incidentGr.resolved_by = gs.getUserID();
// data.isIncidentResolved = incidentGr.update();
// }
if (input && input.action == 'reopenIncident' && incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "write")) {
incidentGr.incident_state = global.IncidentState.IN_PROGRESS;
incidentGr.state = global.IncidentState.IN_PROGRESS;
data.isIncidentReopened = incidentGr.update();
gs.addInfoMessage(gs.getMessage("Request reopened"));
}
if (input && input.action == 'closeIncident' && incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "write")) {
incidentGr.incident_state = global.IncidentState.CLOSED;
incidentGr.state = global.IncidentState.CLOSED;
data.isIncidentClosed = incidentGr.update();
}
if (input && input.action === 'escalateIncident') {
gs.info(JSON.stringify(input))
var gr = new GlideRecord('incident');
if (gr.get(incidentSysId)) { // Ensure data.sys_id is set in the widget context
var comment = 'Selected Option: ' + input.selectedOption + '\nDetails: ' + input.freeText;
gr.comments = comment;
gr.update();
} else {
gs.log('Incident not found for sys_id: ' + data.sys_id); // Debug
}
}
/* Actions - End */
/* Load incident data */
if (incidentGr.get(incidentSysId) && hasPermissions(incidentGr, "read")) {
var incidentUtils = new global.IncidentUtils();
//data.canResolve = incidentUtils.canResolveIncident(incidentGr);
data.canReopen = incidentUtils.canReopenIncident(incidentGr);
data.canClose = incidentUtils.canCloseIncident(incidentGr);
data.canEscalate= incidentGr.getValue('u_escalated')=='0'?true:false;
data.showActions = /*data.canResolve ||*/ data.canReopen || data.canClose || data.canEscalate;
}
function hasPermissions(gr, operation) {
if (operation == "read" && gr.canRead())
return true;
if (operation == "write" && gr.canWrite())
return true;
return (gr.getValue("caller_id") == gs.getUserID()) || (gr.getValue("opened_by") == gs.getUserID());
}
data.i18n = {};
})();
Cilient Controller:
function incidentTicketActions($scope, $http, spUtil, $timeout, spModal, i18n, $window, $uibModal, spAriaUtil) {
/* widget controller */
var c = this;
c.doneLoading = false;
//c.resolvedIncidentMsg = "${Resolved Incident}";
c.closedIncidentMsg = "${Closed Incident}";
c.reopenedIncidentMsg = "${Reopened Incident}";
var MOBILE_DEVICE_SCREEN_WIDTH = 767;
$scope.mobileDevice = c.data.isMobile || ($window.innerWidth < MOBILE_DEVICE_SCREEN_WIDTH);
// $scope.resolveIncident = function() {
// $scope.data.action = 'resolveIncident';
// $scope.server.update(init).then(function(response){
// if (response.isIncidentResolved)
// spAriaUtil.sendLiveMessage(c.resolvedIncidentMsg);
// });
// $scope.$emit('focusOnActions', {"isFocusRequired": true});
// };
$scope.closeIncident = function() {
$scope.data.action = 'closeIncident';
$scope.server.update(init).then(function(response) {
if (response.isIncidentClosed)
spAriaUtil.sendLiveMessage(c.closedIncidentMsg);
});
var elm = document.getElementById('short-desc')
elm.focus();
};
$scope.reopenIncident = function() {
$scope.data.action = 'reopenIncident';
$scope.server.update(init).then(function(response) {
if (response.isIncidentReopened)
spAriaUtil.sendLiveMessage(c.reopenedIncidentMsg);
});
$scope.$emit('focusOnActions', {
"isFocusRequired": true
});
};
$scope.escalateIncident = function() {
$scope.data.action = 'escalateIncident';
var c = this;
spModal.open({
title: 'Add Work Note',
widget: 'select_box2',
size: 'md',
buttons: [{
label: 'Cancel',
cancel: true
},
{
label: 'Submit',
primary: true
}
]
}).then(function(response) {
console.log('Parent: Received shared data:', response);
if (response) {
c.server.get({
action: 'escalateIncident',
})
c.server.update();
} else {
console.log('Parent: No valid data received');
}
});
};
function init() {}
$(document).on('click', 'div.modal-footer button.btn, ul#child-case-tabs .dropdown-menu', function(e) {
e.stopPropagation();
});
$(document).bind('dragover drop', function(event) {
event.preventDefault();
return false;
});
$scope.$on('sp_loading_indicator', function(e, value) {
if (!value && !c.doneLoading) {
c.doneLoading = true;
}
});
}
And child Widget where the modal is build:
BODY:
<div class="simple-incident-form-container">
<div class="panel panel-default">
<div class="panel-body">
<form name="incidentForm" novalidate>
<!-- Select Box (Mandatory) -->
<div class="form-group">
<label>Select Option <span class="required"></span></label>
<select ng-model="c.data.selectedOption"
name="selectOption"
class="form-control"
required
ng-options="option.value as option.label for option in c.data.options">
<option value="" disabled selected>Select an option</option>
</select>
</div>
<!-- Free Text Field -->
<div class="form-group">
<label>Additional Details</label>
<textarea ng-model="c.data.freeText"
name="freeText"
class="form-control"
rows="3"></textarea>
</div>
</form>
</div>
</div>
</div>
Client Controller:
api.controller = function($scope, spUtil) {
var c = this;
// Initialize data
c.data = {
options: [
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2' },
{ value: 'option3', label: 'Option 3' }
],
selectedOption: '',
freeText: ''
};
// Debug changes
$scope.$watch('c.data.selectedOption', function(newVal) {
console.log('Child: Selected Option changed to:', newVal);
c.data.selectedOption=newVal;
});
$scope.$watch('c.data.freeText', function(newVal) {
console.log('Child: Free Text changed to:', newVal);
c.data.freeText=newVal;
});
};
The problem is that after entering the value in the widget:
The result in comment are:
Instead values inserted in window.
Can anyone show me where is the problem?
0 REPLIES 0