Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

SN Record picker value does not write to record

JC S_
Mega Guru

We tried to use sn record picker to allow users to close a change request. So we presented them 2 fields to populate when they try to close the change request:

  1. Close Code
  2. Close Notes

Problem is when they submit, nothing is being written for close_code on the change_request record, only the close_notes. Here's the relevant code from our widget:

HTML

<div class="row">
    	<span class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': field.mandatory_filled()}" style="padding-right: .25em" aria-label="Mandatory " aria-hidden="false"></span>
      <label class="field-label" for="close_code">${Close Code}</label>
      <sn-record-picker field="close_code" table="'sys_choice'" placeholder="${Select a close code}" display-field="'label'" value-field="'value'" default-query="'name=change_request^element=close_code^inactive=false'"></sn-record-picker>
      <input class="form-control" ng-model="c.data.closecode" type="hidden" />
    </div>
    <br/>
    <div class="row">
    	<span class="fa fa-asterisk mandatory" ng-class="{'mandatory-filled': field.mandatory_filled()}" style="padding-right: .25em" aria-label="Mandatory " aria-hidden="false"></span>
      <label class="field-label" for="close_code">${Close Notes}</label>
      <textarea class="form-control" ng-model="c.data.closenotes"></textarea>
    </div>

<button class="btn btn-primary" ng-click="c.uiAction('close')">${Submit}</button>

Client Script

if(action == 'close'){
			// Close the Change Request
			if(c.data.closenotes == undefined || c.data.closecode == '') {
				(alert("Please fill-out mandatory fields"));
				return;
			}
			c.data.action = action;
			c.server.update().then(function() {
				c.data.action = undefined;
			})
		}

Server Script

if (action == 'close' && gr.active == true && gr.state != 4) {
				gr.setValue('state', '3');
				gr.setValue('close_code', input.closecode);
				gr.setValue('close_notes', input.closenotes);
				gr.update();
}

 

 

1 ACCEPTED SOLUTION

Hi JC,

I observed that you are accessing the closecode.

but in the html there is nothing getting passed on it form the SN-RECORD-PICKER.

 

I added following in the sn record picker and accessed it.

<sn-record-picker field="c.data.close_code" table="'sys_choice'" placeholder="${Select a close code}" display-field="'label'" value-field="'value'" default-query="'name=change_request^element=close_code^inactive=false'"></sn-record-picker>

input.close_code.value.

Check if this helps.

 

Best Regards,

Harshad

 

View solution in original post

6 REPLIES 6

Harshad Wagh
Tera Guru

can you check if there is any data coming up in input.closecode?

 

may be add a gs.addInfoMessage to debug it?

 

thanks

Harshad

Confirmed that nothing was being passed by input.closecode. Any ideas on where we went wrong on our code?

Hi JC,

I observed that you are accessing the closecode.

but in the html there is nothing getting passed on it form the SN-RECORD-PICKER.

 

I added following in the sn record picker and accessed it.

<sn-record-picker field="c.data.close_code" table="'sys_choice'" placeholder="${Select a close code}" display-field="'label'" value-field="'value'" default-query="'name=change_request^element=close_code^inactive=false'"></sn-record-picker>

input.close_code.value.

Check if this helps.

 

Best Regards,

Harshad

 

Awesome! Thanks for this.