How to fetch reference/select fields values from widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 05:49 AM
Dear experts,
I have a widget, where there are string fields as well as Select fields (basically reference values in it). When I try to fetch values of a record submitted through this form, I am able to fetch the string values, but not able to fetch the reference or select values.
<div class="form-group col-md-6">
<lable>Site IT Manager </lable>
<select name="site_manager" class="form-control">
<option ng-value="MEP 1 "ng-repeat = "userName in data.owner">{{userName.name}} </option>
</select>
</div>
// with below code, we are getting options in fields on client side.
(function() {
data.owner = [];
var user = new GlideRecord('sys_user');
user.orderBy('number');
user.query();
while (user.next()) {
var userName = {};
userName.name = user.getValue('first_name') + " " +user.getValue('last_name');
data.owner.push(userName);
}
// here we are trying to fetch the given/selected value
if(input){
gs.addInfoMessage("name "+input.site_manager);
var acc = new GlideRecord('x_int46_flex_2_0_account_management');
acc.site_manager = input.site_manager;
acc.account_description = input.myTextareaModel;
acc.mep_cc = input.mep_code;
acc.account_owner=input.acc_owner;
acc.insert();
}
Values populating in reference/select fields.
Please check the info message returning undefined value.
Kindly guide.
Regards,
Ayushi Singhal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 05:53 AM
Did you check the values are sent correctly from client controller to server script?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 06:08 AM - edited 02-28-2023 06:09 AM
// Client script
function($scope) {
var c = this;
// update the server
$scope.passData = function(){
c.server.update();
}
}
Hi @Ankur Bawiskar , Thankyou for your reply.
I only have written this in client script. Can you please let me know if anything needs to add there?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 06:55 AM
unless you send how will server script know
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 12:16 AM
I got it, I was missing sp-model in html, that was causing the issue. Never mind, Thankyou @Ankur Bawiskar for your time. 🙂