
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2020 07:14 AM
Hi all,
I am trying to pass the variables for an RITM to a modal window so that when the user clicks a button, they see the variables in a sort of summary table view. I get the modal to open up but I am not understanding how to pass the variable values to the modal window. Note - this is from an approval record and I am trying to access the RITM variables to show the approver before they approve the record.
This is what I currently have:
<button type="button" ng-click="c.openDetailsModal(approval.sys_id)">View</button>
client script
c.openDetailsModal= function(id) {
console.log(id); //this shows me the correct sys id for the approval
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});
}
Template - here is where I am trying to at least get the task number to show up but it doesn't
<script type="text/ng-template" id="modalTemplate">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Modal Window {{m.task.number}}</h4>
</div>
<div class="panel-body wrapper-xl">
<h4><b>{{::approval.task.cat_item}}</b></h4>
<h4>Summary</h4>
<div ng-if="approval.variables.length > 0" ng-init="variable_toggle=true">
<div ng-repeat="variable in approval.variables" ng-if="variable_toggle">
<div ng-if="variable.name.indexOf('label_') == -1 && variable.name.indexOf('x_') == -1 && variable.value != 'false'">
<table>
<tr>
<td><label style="color:black">{{::variable.label}}: </label></td>
<td><div><label style="color:gray">{{::variable.display_value}}</label></div></td>
</tr>
</table>
</div>
</div>
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeModal()">${Close Modal}</button>
</div>
</div>
</script>
Any suggestions on how I could do this?
Thank you!!
Yen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2020 09:31 AM
Ok so a couple things...
c.openDetailsModal= function(id) {
console.log(id); //this shows me the correct sys id for the approval
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope
});
}
When you assign the scope of the modal to "$scope", "$scope" is the widget $scope service, which we use for a multitude of things (including modals) and WOULD pull the right information for you, but because of how your server script is laid out, I assume the HTML that calls that function is within an ng-repeat. Ng-repeats actually create their own child scope, so "$scope" is actually the parent scope of the scope you are trying to read here. I recommend either utilizing the "c" object variable to pass the approval record to the modal, or pass the approval record as a parameter into the "c.openDetailsModal" function and write a "$scope.approval = [approval record function parameter name here]". If you go with the second option, I strongly recommend clearing $scope.approval once the modal closes, it helps with consistency and will save you some headache in the long run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 07:49 AM
Hi Justin,
I do have same requirement but when i tried passing the value to function. In the console , it is showing as "undefined".
Thanks in Advance...!!
Regards
Nagaraju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 07:55 AM
Can I see your HTML and client code? And could you be a bit more specific as to which function and which log in the console?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 07:59 AM
Here is the code:
<div>
<div class="panel-heading bg-primary">
My Incidents
</div>
<table class="table table-hover jeopardy">
<tr>
<th>Number</th>
<th>Short Description</th>
<th>Edit section</th>
</tr>
<tr ng-repeat="incident in data.list" >
<td>{{incident.number}}</td>
<td>{{incident.shortdescription}} </td>
<td>
<div class="btn btn-primary btn-sm" >
<span Value="" id='copytext' ng-click="c.openModalupdate(c.incident.sysID); reply_click(this.value)" class="fieldLink" >
<i class="fa fa-edit"></i> Edit
</span>
</div>
</td>
</tr>
</table>
</div>
<--popup-->
<script type="text/ng-template" id="openeditmodulepopup">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Please update you current records here</h4>
</div>
<div class="panel-body wrapper-xl">
<sp-model id="widget-form" form-model='data.formOptions'></sp-model>
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeChange()">${Close}</button>
</div>
</div>
</script>
server script:
(function() {
/* populate the 'data' object */
// data.table = $sp.getValue('table');
//data.sys_id=$sp.getValue("sys_id");
var list = [];
var inc = new GlideRecord('incident');
inc.addQuery('priority', '4');
inc.query();
while (inc.next()) {
var obj = {};
obj.number = inc.getDisplayValue('number');
obj.shortdescription = inc.getDisplayValue('short_description');
obj.sysID = inc.getDisplayValue('sys_id');
//gs.addInfoMessage(obj.sysID);
list.push(obj);
}
data.table = 'incident';
data.sys_id = inc.sys_id;
data.query = '';
data.view = 'default';
data.formOptions = $sp.getForm(data.table, data.sys_id, data.query, data.view);
data.list = list;
})();
client code:
function($scope, $window, $uibModal, spUtil) {
/* widget controller */
var c = this;
$scope.$on('record.updated', function(name, data) {
if(c.data.action == 'update'){
c.data.action = undefined;
}
spUtil.update($scope);
});
c.uiActionupdate = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
});
c.modalInstance.close();
};
c.openModalupdate = function(id) {
alert(id);
console.log(id);
c.modalInstance = $uibModal.open({
templateUrl: 'openeditmodulepopup',
scope: $scope
});
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 08:17 AM
ignore the above one, able to getting the sys_id of the record correctly but not sure why the model window is still showing the same record always.
html code:
<div class="btn btn-primary btn-sm" >
<span Value="" id='copytext' ng-click="c.openModalupdate(incident.sysID); reply_click(this.value)" class="fieldLink" >
<i class="fa fa-edit"></i> Edit
</span>
</div>
</td>
</tr>
</table>
</div>
<--->
<script type="text/ng-template" id="openeditmodulepopup">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Please update you current records here</h4>
</div>
<div class="panel-body wrapper-xl">
<sp-model id="widget-form" form-model='data.formOptions'></sp-model>
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeChange()">${Close}</button>
</div>
client code:
function($scope, $window, $uibModal, spUtil) {
/* widget controller */
var c = this;
$scope.$on('record.updated', function(name, data) {
if(c.data.action == 'update'){
c.data.action = undefined;
}
spUtil.update($scope);
});
c.uiActionupdate = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
});
c.modalInstance.close();
};
c.openModalupdate = function(id) {
c.modalInstance = $uibModal.open({
templateUrl: 'openeditmodulepopup',
scope: $scope
});
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2020 08:25 AM
I'd check where that value is being populated. So in your modal's template, is that all information that is stored in scope? If so, make sure you are setting all the scope information when you open your modal.