TPRM - Create a parent-child reference type fields in the Assessment metric survey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 10:46 PM
Hi everyone,
We have a requirement of creating a parent-child reference type fields in the Assessment metric survey (like : Assignment group and Assigned to works on incident form). Field A (parent) refere to group table and field B (child) refere to user table.
On change of A the option of B should be only that group members. OOB there is no option of adding client script on Assessment metric table and no depends on option.We can't add reference qaualifier also.
Only way is to add the code on the widget..We have Copy of Take questionnaire widget in which i tried to fetch the parent field A value on change in the client controller using $scope.$watch. Find the code below as it is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2025 11:25 PM
Hello @Ssinha4
Try below code in client side -
// Inside your widget client controller
function($scope, spUtil, $http) {
// Watch the group field (A)
$scope.$watch('data.fieldA', function(newVal, oldVal) {
if (newVal && newVal !== oldVal) {
// Call server to get users in this group
getUsersForGroup(newVal);
}
});
function getUsersForGroup(groupSysId) {
var url = '/api/now/table/sys_user_grmember?sysparm_query=group=' + groupSysId + '&sysparm_fields=user&sysparm_limit=100';
$http.get(url).then(function(response) {
var userList = [];
if (response.data && response.data.result) {
response.data.result.forEach(function(item) {
userList.push(item.user);
});
}
$scope.filteredUsers = userList; // Bind this to a dropdown/select model
});
}
}
Below in HTML -
<!-- Parent Group Field (Field A) -->
<select ng-model="data.fieldA" ng-options="g.sys_id as g.name for g in data.groupList"></select>
<!-- Dependent User Field (Field B) -->
<select ng-model="data.fieldB" ng-options="u.value as u.display_value for u in filteredUsers"></select>
I have used "REST API" to fetch records because we cannot used GlideRecord in Client side.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2025 01:07 AM
Hi Shivalika,
Thanks for your solution. This $scope.$watch is not working. I think that the issue might with data.fieldA as from widget it is not fetching the name of assessment metric. Is there any workaround with sys_id of the metric. Find the metric screenshot.