- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 05:33 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 04:45 PM
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>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 05:07 AM
No, it does not have to by sys_idIN because when you are calling a javascript function it works with the = even if the result returned is an array (array and not comma separated string).
What I proposed is a Script Include (object from the platform) and not the Server Script. The script include defined should have the client callable checkbox set to true. You could do it using a server script but it would require the function listening for the field.change to make a server update in the widget that would return the answer in the data object. However, this add complexity that I consider is not needed.
Here is a screenshot of the OOTB function:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 11:23 PM
Thanks for sharing.
It is working fine.
But I have a question. How the script include is running where as there is no Class Name or Prototype declared. And If I also write a code for an incident creation whenever the script will run. It is not working.
Have a look.
I just wrote the incident insertion code above the code you have provided. Your code below is working fine in the portal but incident insertion is not happening.
If the script include is been called from portal then it should run all the lines of that script include. But it is just evaluating your part, not mine.
So would you please make me understand what is happening here and what type of script include is this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 05:10 AM
This script is actually a server side script running with the user's ACL in sandbox mode. Which means the script cannot create any record in the system (even logs I think). It is mainly used for filter rules. This function does not have a class defined but it could have one and still work it is simply not required and is easier to call as a simple function.
So this kind of script include is not the same as a Ajax (GlideAjax) script include. If you need to insert incident, you should rather use the server script of the widget.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 09:19 PM
Thanks a ton,
It really helped me a lot. I didn't have a concept of this kind of Script. Can you share any link from where I can Explore more about this?
Thanks and Regards,
Saptashwa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 02:19 PM
I'm not aware of any official documentation about this (other than the documentation of the client callabale checkbox in the documentation of the script include). However, there is many blog/unofficial documentation about this. This is one: https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-scri...