Dynamic sn-record-picker fields

amaradiswamy
Kilo Sage

Hi All,

I want to create two reference fields which depends on other like user and task. When i select user then in task field only tickets raised by him should be visible.

Also, providing a button "Add Row" if user clicks on this then new two fields will come and same dependency should work for this row also.

I am struggling on assigning field value dynamically to observe and get newvalue that was changed. Please help me to solve this issue.

<tr ng-repeat="rowCounter in table_data track by $index" id="tableRow_{{rowCounter.number}}">              

                  <td ng-repeat="columnObj in rowCounter.fields">

                     

                      <div class="form-group" ng-class="{'has-success' : columnObj.value != ''}">

                          <span ng-switch="columnObj.type">

                              <span ng-switch-when="reference">

                                 

                                  <sn-record-picker field="ed_user" table="columnObj.table" display-field="columnObj.displayField" value-field="columnObj.valueField" search-fields="columnObj.searchFields" name="columnObj.name" default-query='' page-size="100" ng-if="columnObj.table == 'sys_user'" id="user" on-change="c.getLaptopDetails(table)"></sn-record-picker>

                                  <sn-record-picker field="columnObj.value" table="columnObj.table" display-field="columnObj.displayField" value-field="columnObj.valueField" search-fields="columnObj.searchFields" name="columnObj.name" default-query="'assigned_to='+user" page-size="100" ng-if="columnObj.table != 'sys_user'"></sn-record-picker>

                              </span>

                              <span ng-switch-when="number">

                                  <input type="number" ng-class="{'form-control-success':columnObj.value > 0}" max="{{columnObj.max}}" min="{{columnObj.min}}" class="form-control" ng-model="columnObj.value" />

                              </span>      

                                <span ng-switch-when="checkbox">

                                  <input type="checkbox" ng-class="{'form-control-success':columnObj.value > 0}" max="{{columnObj.max}}" min="{{columnObj.min}}" class="form-control checkbox" ng-model="columnObj.value" />

                              </span>  

                              <span ng-switch-default="">

                                  <input type="text" ng-class="{'form-control-success':columnObj.value != ''}" class="form-control" ng-model="columnObj.value" />

                              </span>

                          </span>

                      </div>

                  </td>

Client Controller:

$scope.ed_user ={

name: 'approver'

}

$scope.$on("field.change", function(evt, parms) {

      if (parms.field.name == 'approver'){

  alert(parms.newValue);

            $scope.user = parms.newValue;

      }

              });

laurentchicoinechiragbagdaichiragb

lchicoineThanks in advance.

Regards

Swamy

1 ACCEPTED SOLUTION

Not sure what you mean by a html variable, you mean a html table?



In the demo widget I made you could display it directly using the $scope.columns array.



Here is the updated HTML code for that example:



<div ng-repeat="column in columns">


  <sn-record-picker field="column.field" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100"></sn-record-picker>  


      <sn-record-picker field="column.field2" table="'task'" display-field="'number'" value-field="'sys_id'" search-fields="'short_description'" default-query="column.queryField2" page-size="100"></sn-record-picker>


</div>


<button ng-click="addRow()">


  Add row


</button>


<table border="1">


  <tr>


      <th>User</th>


      <th>Task</th>


  </tr>


  <tr ng-repeat="column in columns">


      <td>{{column.field.displayValue}}</td>


      <td>{{column.field2.displayValue}}</td>


  </tr>


</table>


View solution in original post

22 REPLIES 22

Hi Chicoine,



It worked perfectly !!



How can i copy data selected by user to a html variable to show data in a table format?



Regards


Swamy


Not sure what you mean by a html variable, you mean a html table?



In the demo widget I made you could display it directly using the $scope.columns array.



Here is the updated HTML code for that example:



<div ng-repeat="column in columns">


  <sn-record-picker field="column.field" table="'sys_user'" display-field="'name'" value-field="'sys_id'" search-fields="'name'" page-size="100"></sn-record-picker>  


      <sn-record-picker field="column.field2" table="'task'" display-field="'number'" value-field="'sys_id'" search-fields="'short_description'" default-query="column.queryField2" page-size="100"></sn-record-picker>


</div>


<button ng-click="addRow()">


  Add row


</button>


<table border="1">


  <tr>


      <th>User</th>


      <th>Task</th>


  </tr>


  <tr ng-repeat="column in columns">


      <td>{{column.field.displayValue}}</td>


      <td>{{column.field2.displayValue}}</td>


  </tr>


</table>


Sorry for the confusion !!



User will select user and task in catalog form through this widget but when user submits form RITM wil be created. In that RITM, the selected data will not be shown as we are not storing the values selected by the user in widget.



so, i want to copy data selected by user to a html type variable and i can show it as a table in RITM. Please help me on this.


find_real_file.png


Regards


Swamy


I tried by creating another array, stored the values selected by user and copied to a HTML type variable. Thanks for your support !!


So you were able to get what you wanted? Just not sure because of your reply where you say you tried, did you succeed?