- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 01:31 AM
Hi all,
I have a record producer on which I want to show the assignment group the HR case will be assigned to.
SO I have a script include within which I am calling a function and then using a onchange client side script to call the script include and display the group in the item.
This is the code for the getAG function in the script include.
getAG: function(){
//var current = this.getParameter('sysparm_current');
gs.debug('HR AG');
var subjectPerson = this.getParameter('sysparm_req_for');
var prodID = this.getParameter('sysparm_prodID');
var contactType = 'Self Service';
//var source = '[producer.source]';
var AG = '';
var grHrService = new GlideRecord('sn_hr_core_service');
grHrService.get('producer', prodId);
var currentServiceTable = grHrService.getValue('service_table');
var currentTopicCategory = grHrService.topic_detail.topic_category.getDisplayValue();
var currentTopicDetail = grHrService.topic_detail.getDisplayValue();
var currentHRServiceName = grHrService.getDisplayValue('name');
var grSubjectPerson = new GlideRecord('sys_user');
grSubjectPerson.get(subjectPerson);
var currentLocation = grSubjectPerson.getValue('location');
var grCase = new GlideRecord(currentServiceTable);
grCase.setValue('hr_service', HrService);
grCase.setValue('contact_type', contactType);
grCase.setValue('source', source);
grCase.setValue('subject_person', subjectPerson);
grCase.setValue('location', currentLocation);
var grAssignmentRule = new GlideRecord('sysrule_assignment');
grAssignmentRule.addActiveQuery();
grAssignmentRule.addQuery('table', '=', currentServiceTable);
grAssignmentRule.orderBy('order');
grAssignmentRule.query();
var filter;
var found = false;
while ( grAssignmentRule.next() && found == false ) {
filter = grAssignmentRule.getValue('condition');
if ( filter == '' ) {
continue;
}
found = GlideFilter.checkRecord(grCase, filter, true);
if ( found ) {
gs.info('HR AG match: ' + grAssignmentRule.getDisplayValue('group'));
gs.log('HR AG match: ' + group);
AG = grAssignmentRule.group;
return AG;
}
}
if ( found == false) {
gs.info('HR AG: no match');
}},
and then this is the client script that is calling the script include function:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('sn_hr_core.HRCaseAccessRP');
ga.addParam('sysparm_name', 'getAG');
ga.addParam('sysparm_req_for', producer.requested_for);
ga.addParam('sysparm_prodID', g_form.getUniqueValue());
ga.getXMLAnswer(getResponse);
function getResponse(response){
var answer = JSON.parse(response);
g_form.addInfoMessage(answer.AG);
g_form.setValue('assignment_group', answer.AG);
}
//Type appropriate comment here, and begin script below
}
so the onchange client script works in the sense it displays the showfield message banner so the blue bit under the field. But there is no data or group shown in the field message. it is blank.
I have added some gs.logs within the script include function I am calling but they are not displaying in the logs at all.
So looks like script include is not being called.
The script include is in the HR core app scope and the client script is in the employee center core scope.
The script include caller access is set to none so that should not restrict and accessible from is all app scopes.
Can someone help me on this please.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 02:41 AM
Hi Khalnayak,
I suppose your code is failing at below highlighted lines as the variable defined is different one here, please make corrections.
Hope this helps.
If my answer resolves your issue, please mark my answer as ✅ Correct & Helpful based on the validations.
Thank You!
Regards,
Kailash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 09:09 AM
I see that, you are passing display value from script include to client script.
Pass sys_id of the group as the field on client side seems to be reference field.(Please confirm if I am considering wrong).
And once you receive the sys_id at client side set it on the field so that field value will come properly.
Hope this helps.
If my answer resolves your issue, please mark my answer as ✅ Correct & Helpful based on the validations.
Thank You!
Regards,
Kailash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 09:47 AM
Hi
yes it is a reference field for group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 08:41 PM
Hi Khalnayak,
I would suggest you to revisit your code as I see lot of basic mistakes done by you.
Please remove the highlighted part as well from your code....
the sample code to return group sys_id is as below(it is for loggedin user), please refer it and modify your code.
var user = gs.getUserID();
gs.print("LoggedInUSer is:- " + user); //02e2fe822fd6f0103011837cf699b623
var gR = new GlideRecord('sys_user_grmember');
gR.addQuery('user', user);
gR.query();
while(gR.next()) {
gs.print(gR.group);
}
Hope this helps.
If my answer resolves your issue, please mark my answer as ✅ Correct & Helpful based on the validations.
Thank You!
Regards,
Kailash