How to call sn-record-picker in client control and server script

keerthi19
Tera Guru

Hi All,

I would like to add 2 columns in my modal window but one column i have added and client and server actions are working fine . But i am not sure how to add one more column in the same window. can anyone help me on this. i would like to call the "sn-record-picker" selected values into client controller modal and update the selected value into server side.

HTML :

<span class="label-text">Add users</span>
<sn-record-picker field="selectedField" table="'sys_user'"
display-field="'label'"
multiple="true"
value-field="'name'"
display-fields="'name'"
search-fields="'label,name'" page-size="100" on-change="c.onChange()" ></sn-record-picker>

Server Side :

data.sys_id = input.item_sys_id || $sp.getParameter("sys_id");
var action = input.action;
var comments=input.value;
var adduser= input.user;
if (action =="moreInformation"){
// Valid GlideRecord
gr = new GlideRecord("sysapproval_approver");
if (!gr.isValid())
return;
// Valid sys_id
if (!gr.get(data.sys_id))
return;
if (input && input.action) {
gs.log("k:inside approve if condition");
if(action == 'moreInformation') {
gr.comments=input.value; //User entered value in model
gr.u_add_user=input.user;
gr.setValue('state', 'more_info_required');
gr.setValue('updated_by', gs.getUserID());
gr.update();
}
}
}

Client Controller :

c.moreInformation=function(action,item_sys_id,value,user) {
spModal.open({title: 'Commetns are Mandatory to reject',
label: 'Comments',
input: true,
value:c.value,
user:c.user
}).then(function(value,user) {
if(value){
c.data.action = action;
c.data.item_sys_id = item_sys_id;
c.data.value = value;
c.data.user = user;
c.server.update().then(function() {
c.data.action = undefined;
})
}
else{
console.log('Comment mandatory');
}
})
c.onChange = function(user) {
c.data.field = c.selectedField.value;
c.server.update().then(function() {
c.data.field = undefined;
})

}
};

 

I have wrote code in Data Table widget after clone.

Current Window :

find_real_file.png

I wants to include that "Add User" field below comments column into the modal window. I have written HTML but not sure how to invoke the values to modal as well as server side. Can anyone give me some clue .it will be great help.

 

 

 

4 REPLIES 4

Siddhnath Pande
Mega Guru

Hi keerthi,

Can you share the code of this above comment model window.

Because there is no relation with CC or SS you just have to put that sn-record-picker html code into this above comment model window's HTML Template/part.

Like here is example:

find_real_file.png

If the above code helps then please mark my answer Correct and Helpful.

Thanks and Regards:
Siddhnath Pandey

 

keerthi19
Tera Guru

Hi Siddhnath,

I am not using html to open model window. The model window is in CC. If you see above code you can get the model widow. Actually I am doing this in Data Table widget . When user right click the each record they should  "More Information" as one of the  option as same as OOB "Filter Out" and "Show Matching" .Those OOB context menus called using Link. So same way i tried to add "more information" option as well its working as expected but what ever value they given in the model window that should be passed to back end table(sysapproval.approver) table. So i wants to send the selected user to back end table and send notification to those users. So  i am not sure how to add it here.

Below is the Link which i am calling in CC.By using CC the model window opens. There i wants to add one more column. basically i wants to enable list field. The record picker is giving result as expected but i don't know how to use it here in my case. Please suggest.find_real_file.png

 

CC:

 

find_real_file.png

 

I tried to find something but i didn't get the suitable answer for you. I am sorry.

However whatever I have found in search I am sharing with you may be you get some help.

The spModal class provides an alternative way to show alerts, prompts, and confirmation dialog. spModel.open takes few specific parameter so we can not add extra like add user. 

So I don't think you can enter some value like add user with in this way

If you haven't checked the spModel doc.  please check this below link

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

 

But there is one way I thought this might work that was emending another custom widget in that window & create that two filed comment & add user on that custom widget. but I don't know much about it.  😞