The CreatorCon Call for Content is officially open! Get started here.

Save user provided comments in custom table field in Portal.

Mad3
Tera Expert

Hello Community,

 

Could help on this!

 

As bigginer to ServiceNow, Developed a clickable button using spModal.open() method in portal.

When click button window is populating inside the window user should provide comments. I am facing difficulty in to store those comments in a server with respect to the record.

The User provided comments should update in table Record.

 

Thanks in Advance!

 
 

Popup-Window.PNG

 
 
 

 

 

HTML:

Mad3_0-1676023112828.png

Client Script:

 

c.reject = function(){
c.comments='';
spModal.open({
title:'Comments',
message:'Please provide comments here:',
input:true,
value:c.comments,
}).then(function(comments){
c.comments=comments;
})

}

 

5 REPLIES 5

Arpitha2
Tera Contributor

Hi @Mad3,

 

I got the solution for this. I have created another widget to open the modal. Below is the snippet.

 

Called Widget:

<div class="form-group">
<label for="pxp_confirm_text" ng-if="options.shared.message">
<span class="field-decorations">
<span ng-if="options.shared.required" class="fa fa-asterisk mandatory" ng-class="{ 'mandatory-filled': options.shared.text.length }" title="Required" style="padding-right: .25em"></span>
{{options.shared.message}}
</span>
</label>
<textarea ng-required="true" id="pxp_confirm_text" type="text" class="form-control" placeholder="{{options.shared.textPlaceholder}}"
autocomplete="off" aria-invalid="{{options.shared.required && !options.shared.text.length}"
ng-model="options.shared.text" ng-required="options.shared.required"/>

 

Calling Widget:

Server Side:

grCase.comments = input.comments;

 

Client Controller:

$scope.cancelCase = function() {
var confirmMsg = $scope.data.i18n.cancelMsgNoChildren;
var title = $scope.data.i18n.cancelTitle;
$http.get(
'/api/sn_hr_core/utils/getGlideRecord?sysparm_name=getGlideRecordSecureSetData&sysparm_tableName=sn_hr_core_case&sysparm_query=active=true^stateNOT IN1,3,4,7^parent=' +
$scope.data.parentCaseId).then(function(response) {
if (response.data && JSON.parse(response.data.result).length > 0)
confirmMsg = $scope.data.i18n.cancelMsgOpenChildren;

var inputOptions = {
message: confirmMsg,
text: '',
textPlaceholder: 'Comments required',
required: true
};
spModal.open({
title: title,
widget: 'cancel_comments',
shared: inputOptions,
backdrop: false, // disable close by click

}).then(function(comments) {
if (!inputOptions.text) {
alert ('Please enter comments');
return false;
}

var payload = {};
payload.name = "My Requests";
payload.data = {};
payload.data["Action"] = "Cancel Request";
payload.data["HR Case"] = $scope.data.recordInfo.number;
payload.data["HR Service"] = $scope.data.recordInfo.hr_service;
payload.data["Short Description"] = $scope.data.recordInfo.short_desc;
snAnalytics.addEvent(payload);
$scope.data.action = 'cancelCase';
$scope.data.comments = inputOptions.text;
$scope.server.update();
});
});
};