How to make Service Portal widget readonly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 06:20 AM
I have added a custom widget in the Service Portal incident page.
I want to make the widget non editable when the incident state is "resolved" or "closed".
Could you please tell how can i achieve this.
Please find the below widget script.
HTML
<div class="panel panel-primary" ng-if="data.canRead">
<div class="panel-heading">
<h4 class="panel-title pull-left">
${Watch list}
</h4>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<form ng-submit="save()">
<div class="text-center text-italic text-muted">
<div>
<sn-record-picker field="watch_list" sn-disabled="!data.canWrite" table="'sys_user'" display-field="'email'" display-fields="'name'" search-fields="'email'" value-field="'sys_id'" default-query="'active=true^web_service_access_only=false^user_nameISNOTEMPTY^emailISNOTEMPTY'" page-size="10" multiple="true"></sn-record-picker> </div>
<div style="margin-top:15px; float: right;">
<button type="submit" class="btn btn-primary post-btn ng-scope">Save</button>
</div>
</div>
</form>
</div>
</div>
Client Script
api.controller=function($scope, spUtil, $http) {
var c = this;
$scope.watch_list = {
displayValue: c.data.displayValue,
value: c.data.value,
name: 'watch_list'
};
$scope.save = function(){
c.data.watchList = $scope.watch_list.value;
c.server.update().then(function() {
spUtil.recordWatch($scope, c.data.table, "sys_id=" + c.data.sys_id, function(name, data) {
if(name.name == 'record.updated' && data.operation == 'update'){
$scope.watch_list.value = data.record.watch_list.value;
$scope.watch_list.displayValue = data.record.watch_list.display_value;
$scope.$apply();
}
});
});
};
$scope.$on("field.change", function(evt, parms) {
if (parms.field.name == 'watch_list') {}
});
};
Server Script
(function() {
var gr;
if(input){
gr = new GlideRecord(input.table);
if(gr.get(input.sys_id)){
if(gr.watch_list.canWrite()){
gr.watch_list = input.watchList;
gr.update();
gs.addInfoMessage('Updated');
}
else{
gs.addErrorMessage("Update failed, you don't have the required access");
}
}
}
else{
var sys_id = (input && input.sys_id) || options.sys_id || $sp.getParameter("sys_id");
var table = (input && input.table) || options.table || $sp.getParameter("table");
gr = new GlideRecord(table);
if(gr.get(sys_id)){
data.table = table;
data.sys_id = sys_id;
data.canRead = gr.watch_list.canRead();
data.canWrite = gr.watch_list.canWrite();
if(data.canRead){
var dV = gr.getDisplayValue('watch_list');
var sV = gr.getValue('watch_list');
//data.displayValue = dV == '' ? [] : dV;
//data.value = sV == null ? [] : sV;
data.displayValue = dV;
data.value = sV;
}
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 06:23 AM
Hi @Bhagya ,
Refer to this thread :https://www.servicenow.com/community/developer-forum/read-only-field-on-service-portal-only/m-p/1773...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 06:45 AM
but i dont have g_form statement in the script.
can u please check my script.