Issue with my widget code

David Cross
Tera Expert

Hello All,

i want to display only the selected users incident number in the page .... But its not showing any value. 

What mistake have i done here, please help

 

Html code:-
<sn-record-picker field="data.user" table="data.user.table"
default-query="data.user.defaultQuery" display-fields="data.user.displayFields" value-field="data.user.valueField"
search-fields="data.user.searchFields" ></sn-record-picker>
<button ng-click="sendData(data.user.value)" value='sd'>sd</button>

<ul>
<li ng-repeat="item in data.items">
<div ng-repeat="field in item">
{{field.name}} : {{field.value}}
</div>
</li>
</ul>

 

Client Side :

api.controller=function($scope) {
  var c = this;
$scope.sendData = function(ss){
data.send=ss;
};
};
 
Server side:
(function() {
  data.user = { 
value:'',
displayValue:'',
name:'user',
table:'sys_user',
valueField:'sys_id',
defaultQuery:'active=true',
displayFields:'name,email',
searchFields:'name,email'
 };
 
data.items =[];
var fields = 'number, caller_id, sys_created, state';
 
var inc = new GlideRecord('incident');
inc.addQuery('active',true);
inc.addQuery('sys_id',data.send); > NOT WORKING 
inc.query();
var item;
while(inc.next()){
item = $sp.getFields(inc, fields);
data.items.push(item);
}
})();
1 ACCEPTED SOLUTION

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @David Cross , 

Use input objects & c.server.update in client side. Thats missing in your code. 

 

Certainly! Here's the complete code with both client-side and server-side scripts:

 

// Client-Side Controller
 
 

 

// Client-Side Controller
api.controller = function($scope, spUtil) {
    $scope.sendData = function(ss) {
        input.data.send = ss;
        // Trigger server-side update
        c.server.update().then(function(response) {
            // Handle server response if needed
        });
    };
};

 

 

HTML Template:

 

 

<!-- HTML code -->
<sn-record-picker field="data.user" table="data.user.table"
    default-query="data.user.defaultQuery" display-fields="data.user.displayFields"
    value-field="data.user.valueField" search-fields="data.user.searchFields">
</sn-record-picker>
<button ng-click="sendData(data.user.value)">Send Data</button>

<ul>
    <li ng-repeat="item in data.items">
        <div ng-repeat="(key, value) in item">
            {{key}}: {{value}}
        </div>
    </li>
</ul>

 

Server-Side Script:

 

 

// Server-Side Script
(function() {
    // Ensure data object exists
    data.user = data.user || {};
    data.items = [];

    // Check if input.data.send exists
    if (input && input.data && input.data.send) {
        var inc = new GlideRecord('incident');
        inc.addQuery('active', true);
        inc.addQuery('caller_id', input.data.send); // Change 'sys_id' to 'caller_id' if you're querying by user ID
        inc.query();

        while (inc.next()) {
            var item = {};
            // Populate item with desired fields
            item.number = inc.number.toString();
            item.caller_id = inc.caller_id.toString();
            item.sys_created = inc.sys_created.toString();
            item.state = inc.state.toString();

            data.items.push(item);
        }
    }
})();

 

Adjust the field names accordingly. This setup allows you to select a user using the record picker, send the selected user's value to the server-side script upon button click, and then populate the data.items array with incident details related to the selected user.

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

3 REPLIES 3

SanjivMeher
Kilo Patron
Kilo Patron

I believe in client controller it should be c.data.send

 

Client Side :

api.controller=function($scope) {
  var c = this;
$scope.sendData = function(ss){
c.data.send=ss;
};
};

Please mark this response as correct or helpful if it assisted you with your question.

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @David Cross , 

Use input objects & c.server.update in client side. Thats missing in your code. 

 

Certainly! Here's the complete code with both client-side and server-side scripts:

 

// Client-Side Controller
 
 

 

// Client-Side Controller
api.controller = function($scope, spUtil) {
    $scope.sendData = function(ss) {
        input.data.send = ss;
        // Trigger server-side update
        c.server.update().then(function(response) {
            // Handle server response if needed
        });
    };
};

 

 

HTML Template:

 

 

<!-- HTML code -->
<sn-record-picker field="data.user" table="data.user.table"
    default-query="data.user.defaultQuery" display-fields="data.user.displayFields"
    value-field="data.user.valueField" search-fields="data.user.searchFields">
</sn-record-picker>
<button ng-click="sendData(data.user.value)">Send Data</button>

<ul>
    <li ng-repeat="item in data.items">
        <div ng-repeat="(key, value) in item">
            {{key}}: {{value}}
        </div>
    </li>
</ul>

 

Server-Side Script:

 

 

// Server-Side Script
(function() {
    // Ensure data object exists
    data.user = data.user || {};
    data.items = [];

    // Check if input.data.send exists
    if (input && input.data && input.data.send) {
        var inc = new GlideRecord('incident');
        inc.addQuery('active', true);
        inc.addQuery('caller_id', input.data.send); // Change 'sys_id' to 'caller_id' if you're querying by user ID
        inc.query();

        while (inc.next()) {
            var item = {};
            // Populate item with desired fields
            item.number = inc.number.toString();
            item.caller_id = inc.caller_id.toString();
            item.sys_created = inc.sys_created.toString();
            item.state = inc.state.toString();

            data.items.push(item);
        }
    }
})();

 

Adjust the field names accordingly. This setup allows you to select a user using the record picker, send the selected user's value to the server-side script upon button click, and then populate the data.items array with incident details related to the selected user.

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Thank You Sohithanjan