How to create a Save button in Service portal view page in service now

Community Alums
Not applicable

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. 

7 REPLIES 7

Karishma5
Tera Expert

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

find_real_file.png

www.dxsherpa.com

 

Community Alums
Not applicable

Thanks Karishma, i will try this. 

Afternoon, 

Did you get this working in the end?

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.