- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2018 02:24 AM
Hi All,
I am new to Service Portal Development so I need all your help.
My requirement is, I need to create two buttons on Catalog item form.
As a part of my requirement I have cloned the OOB widget(Sc- catalog Item) and added the two buttons in the html part as shown in above screen shot.
So when user clicks on the Save as a Template button, a new record should get inserted in the custom table(u
-My templates) and the Current Catalog name should get copied to custom table reference field.
How can I insert the new record in custom table when user clicks on Save as Template Button.
<p style="float: left; width: 130px"><button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('resolve')">Save as a Template</button>
<p style="float: right; width: 130px"><button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('cancel')">Saved for later</button>
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2018 01:30 PM
There's probably going to be a lot more to this that will need to be asked in other forum posts, but here's how you can create a button to insert a record. You can create this as its own standalone widget if you want and then just add that widget to the existing 'sc_cat_item' portal page. The only things you'll need to change below are in the 'Server script' section. You'll need to change 'u_custom_table' to the table name where you want to insert the record and 'u_catalog_item' to the Catalog item reference field on that table. Here are the settings...
Body HTML template:
<div class="panel panel-default">
<div class="panel-heading">Templates</div>
<div class="panel-body">
<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('saveAsTemplate')">Save as Template</button>
</div>
</div>
Server script:
(function() {
// Get table & sys_id
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Initialize GlideRecord
var gr = new GlideRecord('u_custom_table');
gr.initialize();
if (input && input.action) {
var action = input.action;
if (action == 'saveAsTemplate') {
// Create template record
gr.u_catalog_item = data.sys_id;
gr.insert();
}
}
})();
Client controller:
function() {
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2018 01:30 PM
There's probably going to be a lot more to this that will need to be asked in other forum posts, but here's how you can create a button to insert a record. You can create this as its own standalone widget if you want and then just add that widget to the existing 'sc_cat_item' portal page. The only things you'll need to change below are in the 'Server script' section. You'll need to change 'u_custom_table' to the table name where you want to insert the record and 'u_catalog_item' to the Catalog item reference field on that table. Here are the settings...
Body HTML template:
<div class="panel panel-default">
<div class="panel-heading">Templates</div>
<div class="panel-body">
<button type="button" class="btn btn-primary btn-block" ng-click="c.uiAction('saveAsTemplate')">Save as Template</button>
</div>
</div>
Server script:
(function() {
// Get table & sys_id
data.sys_id = input.sys_id || $sp.getParameter("sys_id");
// Initialize GlideRecord
var gr = new GlideRecord('u_custom_table');
gr.initialize();
if (input && input.action) {
var action = input.action;
if (action == 'saveAsTemplate') {
// Create template record
gr.u_catalog_item = data.sys_id;
gr.insert();
}
}
})();
Client controller:
function() {
var c = this;
c.uiAction = function(action) {
c.data.action = action;
c.server.update().then(function() {
c.data.action = undefined;
})
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2018 02:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2020 05:54 PM
HeyAjay,
did you happen to find the answer? to get the variable from the form ?