Update record with c.server.update()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2018 06:39 AM
Hi all,
On out service portal, when you first log into it a modal will appear and ask you to review your information. Upon review, there are two options at the bottom to either dismiss the modal or be sent to a place that will allow them to have the data modified. When they make their choice, their user record is logged in a table "u_sp_modal_user_history" That all works, but it has been tasked of me to add functionality to log the choice they make. The modal was kind of built for us, so I wanted to avoid a total rewrite if I could.
Below is my code for reference.
Client Script:
function($scope, $uibModal, $window) {
/* widget controller */
var c = this;
c.showModal = function() {
if (c.data.showModalProperty == "true") {
if (!c.data.correctInfo) {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope,
bindToController: true,
size: 'lg',
backdrop: 'static', //no background clicks
keyboard: false //disable esc to close modal
});
}
}
}
c.closeModal = function() {
c.data.noError = true;
c.server.update();
c.modalInstance.close();
}
c.redirect = function(){
c.data.noError = true;
c.server.update();
$window.location.href = c.options.redirect_url_if_information_is_incorrect;
}
}
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.users = [];
data.showModalProperty = gs.getProperty('cf.show.profile.modal');
var checkGR = new GlideRecord('u_sp_modal_user_history');
checkGR.addQuery("u_user", gs.getUserID());
checkGR.query();
if (checkGR.next()) {
data.correctInfo = true;
}
var gr = new GlideRecord('sys_user');
gr.addQuery("sys_id", gs.getUserID());
gr.query();
while (gr.next()) {
var user = {};
$sp.getRecordDisplayValues(user, gr, 'user_name ,name, title, phone, u_room__, u_building, u_district');
$sp.getRecordValues(user, gr, 'sys_id');
data.users.push(user);
}
if (input.noError) {
var sp_user = new GlideRecord('u_sp_modal_user_history');
sp_user.initialize();
sp_user.u_user = gs.getUserID();
sp_user.insert();
}
})();
My initial thought was to use the c.server.update() in both of the two client functions to take the logged data in with it. The end goal however is basically to populate the field "u_option_chosen" on the table with either "Red" or "Green" depending on the option chosen.
Thanks!
-Justin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 08:04 AM
Hey Justin,
I think you shouldn't have to do too much modifying. As long as you know when the "Red" or "Green" is supposed to be entered then it should be possible to just add that bit into the GlideRecord update. ie: sp_user.u_option_chosen = "Green".