How to insert text of textarea on Service Portal into a table record

pallavi11
Kilo Contributor

I have created a textarea on Service Portal to retrieve rejection comments whenever any user rejects any approval.. i want to copy the rejection comments on approval table activity log. I am new to Service Portal please guide how to work on this requirement.

4 REPLIES 4

nayanawadhiya1
Kilo Sage

Update those comments to Worknotes of the approval table then it automatically shown in the Activity Log. 

Karishma5
Tera Expert

Hi Pallavi,

You can retrieve the comments on approval activity log from sys_journal_field table. In service portal, in Server script you have to write the following code, if the approval gets rejected :

 

var gr= new GlideRecord('sys_journal_field');
gr.addQuery('element_id','<sys_id of the rejected approval>');
gr.query();
while(gr1.next()){
data.comment=gr1.getValue('value');   // push approval comment in the data object
}

 

In the HTML , you need to bind the textarea element with data.comment as follows:

<textarea ng-model="data.comment"></textarea>

 

Hope it helps!

 

Regards,

Karishma

Have a doubt.. here you have created a glide object-'gr' then what is 'gr1' in if statement? Is it a typo?

Also i want to push textarea comment on approval worknotes. 

hi pallavi,

Yes sorry that was a typo. And About the pushing the text area into worknotes you have to do as follows:

in HTML :

add ng-change which will call that specified function in client script.

<textarea ng-model="data.comment" ng-change="c.update()"></textarea>

In client script:

define the function that we will be calling from HTML i.e.  c.update()

function(spUtil) {
/* widget controller */
var c = this;

c.update=function(){
c.server.get({
action:'update',
sys_id:c.data.approval[0].sys_id,
comment:c.data.approval[0].value

}).then(function(response){
spUtil.addInfoMessage("your record has beeen updated")
});

}

 

In Server Script:

In the previous server script you can add the below code:

if(input.action=="update"){
var gr2= new GlideRecord('sys_journal_field');
gr2.get(input.sys_id);
gr2.setValue('value',input.comment);
gr2.update();

}

}

 

Hope it helps.