How to get the value of a Dropdown on a widget to a field on the table

F_bio Santos
Kilo Sage

 Im trying to get the value of a dropdown that is in a widget to the "Assign to" of a table but Im not sure how to get that value.

Code:


Widget HTML :

 

<div class="panel panel-default">
 <div class="panel-heading">Atribuir a</div>
 <div class="panel-body">
  <sn-record-picker id="assigned-to"
                            field="c.AssignedTo"
                            table="'sys_user'" 
                            display-field="c.data.reqForDispCol" 
                            display-fields="c.data.reqForDispCols" 
                            value-field="'sys_id'" 
                            search-fields="c.data.reqForSearchCols"
                            default-query="c.data.reqForQuery"
                            page-size="100"
                            options="{allowClear : false}"
					</sn-record-picker>
   <br>
<button type="button" class="btn btn-default btn-block" ng-click="c.uiAction('assign_to')">Assign to</button>
   
  </div>
</div>

 

 

Server Script:

 

(function() {

    // Get table & sys_id
    data.table = $sp.getParameter("table");
    data.sys_id = $sp.getParameter("sys_id");

    // Valid GlideRecord
    gr = new GlideRecord(data.table);
    if (!gr.isValid())
        return;

    // Valid sys_id
    if (!gr.get(data.sys_id))
        return;

    data.state = gr.getValue('Assigned To');
    if (input && input.action) {
        var action = input.action;



        if (action == 'assign_to') {
            gr.setValue('assigned_to', assign_to);
            gr.update();
        }
    }

})();

 

 

Client Controller:

 

 

api.controller = function() {
    var c = this;
    c.action = function(assigned_to) {
        c.data.assigned_to = assigned_to;
    };
	
    c.uiAction = function(action) {
        c.data.action = action;
        c.server.update().then(function() {
            c.data.action = undefined;
        });
    };
};

 

 

Dropdown on portal:

F_bioSantos_0-1690466615152.png

Error that I get in the portal:

 

F_bioSantos_0-1690475555382.png

 

 

0 REPLIES 0