Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to fetch reference/select fields values from widget

Ayushi Singhal
Giga Contributor

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.

 

AyushiSinghal_1-1677591664082.png

 

Please check the info message returning undefined value.

 

AyushiSinghal_2-1677591703594.png

 

Kindly guide.

 

Regards,

Ayushi Singhal

 

 

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@Ayushi Singhal 

Did you check the values are sent correctly from client controller to server script?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

 

// 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? 

@Ayushi Singhal 

unless you send how will server script know

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I got it, I was missing sp-model in html, that was causing the issue. Never mind, Thankyou @Ankur Bawiskar for your time. 🙂