- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 08:02 AM
Hi,
I have a script include which get the group from assignment rules. And then I need to display this group in the record producer form in portal.
The script include works because when I do a gs.info it is showing the group name. but issue I am having is when assigning the returned value to a variable/object it does not seem to store it.
When I do a gs.info on the variable it is saying undefined.
Also in client script not showing group name.
script include function:
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', currentHRServiceName);
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.getDisplayValue('group');
return AG;
}
}
if ( found == false) {
gs.info('HR AG: no match');
}},
client script:
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', g_form.getValue('requested_for'));
ga.addParam('sysparm_prodID', g_form.getUniqueValue());
ga.getXMLAnswer(getResponse);
function getResponse(response){
var answer = JSON.parse(response);
g_form.showFieldMsg('assignment_group',answer,'info');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:45 AM
Hi,
you didn't share what came in alert for response?
use this
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', g_form.getValue('requested_for'));
ga.addParam('sysparm_prodID', g_form.getUniqueValue());
ga.getXMLAnswer(function(answer){
alert(answer);
g_form.showFieldMsg('assignment_group',answer,'info');
});
}
Also share gs.info() for this
if ( found ) {
AG = grAssignmentRule.group.name;
gs.info("AG->" + AG);
return AG;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 08:40 PM
Hi,
if you are in scoped app don't use gs.info()
what came in logs?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 01:02 AM
Hi
Wierd thing is, I just commented out all the gs.info logs in my script include and now I get a a javascript browser error on the record producer in portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:04 AM
Hi,
so what's coming in alert for response?
whats the browser console error?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:14 AM
okay so no error when I comment out gs.info, I get error when I comment out gs.log.
error in console is:
The unhandled exception in GlideAjax is the one that is new, the top has been there for a while.
And If I uncomment the gs.log then I can see the showfieldmessage but it says null rather than displaying group name.
and in the browser console I get null too for logging the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:29 AM
Hi,
don't use gs.log() in script include but use gs.info()
Now null means the script include function is not returning the correct field value or the field name is incorrect
use this
if ( found ) {
gs.info('HR AG match: ' + grAssignmentRule.getDisplayValue('group'));
gs.log('HR AG match: ' + group);
AG = grAssignmentRule.group.name;
return AG;
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader