How to create a Save button in Service portal view page in service now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2018 06:12 AM
I need to create a Save button in Service portal view page in service now from where user needs to update the details and then submit it for action.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 12:36 AM
Hi Amit,
You can create a save button in service portal by adding the following code into your widget . Just providing a sample code, You can modify it as per you requirement.
In HTML:
<input type="text" ng-model="c.data.name">
<button type="button" class="btn btn-default" ng-click="c.Save()" >save</button>
In Client Script:
c.Save=function(){
c.server.get({
action:'update',
name :c.data.name // example
//define the values which you want to save in key-value pair to the
}).then(function(r){
});
In Server Script:
if(input.action=='update'){
var gr=new GlideRecord('<table name in which you are saving the details>');
gr.get(<sys_id of the record you are updating>);
gr.setValue('u_name',input.name);
gr.update();
}
Hope it helps.
Regards,
Karishma Horo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 12:41 AM
Thanks Karishma, i will try this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2019 06:13 AM
Afternoon,
Did you get this working in the end?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2019 11:30 AM
i have used above script.but it is not working
i have added information in all form fields and clicked on Save button . but it is not Saving form
<input type="text" ng-model="c.data.name">
<button type="button" class="btn btn-default" ng-click="c.Save()" >save</button>
c.Save=function(){
c.server.get({
action:'update',
name :c.data.name // example
//define the values which you want to save in key-value pair to the
}).then(function(r){
});
(function() {
// Get table & sys_id
data.table = input.table || $sp.getParameter("table");
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Valid GlideRecord
gr = new GlideRecord(data.table);
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
//Button Visibility
if (data.table == 'u_my_shuttle_requesting' && gr.u_state=='Update Needed' && gr.u_requestor_name == gs.getUserID()) {
data.showButton=true;
}else{
data.showButton=false;
}
if (input && input.action) {
var action = input.action;
// If table
if (data.table == 'u_my_shuttle_requesting') {
if (action == 'update') {
gr.setValue('u_name',input.name);
gr.update();
data.fltr='/shuttle_request/?id=shuttle_request';
}
}
}
})();
form Not Saved.