Can you use g_form in a script include?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 04:01 PM
I am running a script include to check the current user and display assignment groups accordingly. I now have a requirement to look at the current customer on the form first before searching the user and then display assignment groups based upon that customer.
For this I have made a new table u_customer_assignment_groups(not a reference table), with 2 fields customer and group where end users will be able to connect customers with groups. So I am trying to get my Script Include to look at the current customer on the form then look through the table and if the customer is in the table then display the groups listed with the customer.
In my script include I try to call g_form, but I don't think you can call this in a Script Include. So does anyone have any suggestions on how to run through this.
getGroupsOfType: function (groupTypes) {
/*look here for customer on the other table to make*/
var groups2;
var currComp = g_form.getValue('company');//returns an error
gs.log(currComp);
var grGroups4 = new GlideRecord('u_company_assignment_groups');
grGroups4.addQuery('u_company', currComp);//filter on the current company
grGroups4.query();
if(grGroups4.next()){
while(grGroups4.next()) {
groups2.push(grGroups4.getValue('sys_id'));
}
return groups2; // return the groups assocaited with the customer in the table
}
//this part below is working fine for me. Just this part above ^^
var groups = [];
var isdType = "63600de5db6673c0192a6ac2ca961999"; //ISDagent group type sys_id
var nocType = "9d5089e5db6673c0192a6ac2ca9619bd"; //NOCagent group type sys_id
var index = groupTypes.toString().split(',').indexOf(isdType) > -1;
var index2 = groupTypes.toString().split(',').indexOf(nocType) > -1;
gs.log(index);
gs.log(index2);
gs.log(groupTypes);
if(index){//show isd agent groups only
var grGroups = new GlideRecord('sys_user_group');
grGroups.addQuery('type','CONTAINS','e797a021dbddbb00192a6ac2ca96198d');//show ISD group type
grGroups.query();
while(grGroups.next()) {
groups.push(grGroups.getValue('sys_id'));
}
return groups;
}
else if(index2){//show noc agent groups only
var grGroups2 = new GlideRecord('sys_user_group');
grGroups2.addQuery('type','CONTAINS','5c330789db2233c0192a6ac2ca9619a9');//show NOC group type
grGroups2.query();
while(grGroups2.next()) {
groups.push(grGroups2.getValue('sys_id'));
}
return groups;
}
else{ //show itsm groups
var grGroups3 = new GlideRecord('sys_user_group');
grGroups3.addQuery('type','CONTAINS','efa71a776f7f21406ca6687f8e3ee48d');//itsm sys_id
grGroups3.query();
while(grGroups3.next()) {
groups.push(grGroups3.getValue('sys_id'));
}
return groups;
}
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 04:14 PM
Hi,
Without reading the entire post and based off the topic title alone, no, you can't use g_form in script include as it's server side script. You can initiate the script include from the reference qualifier section of the field and use "current".
Example here: https://community.servicenow.com/community?id=community_question&sys_id=6740c7a1db98dbc01dcaf3231f96...
Please mark reply as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 04:34 PM
Ahh okay, so if I have to pass current in the reference qualifier below
Then I would put current in getGroupsOfMyTypeQuery beginning function. So how would I get current to the desired function I would want? In this case it would be getGroupsOfType function at the bottom (I took out the code to hopefully make it easier to understand what I am looking for)
javascript:new GetGroupsOfTypeRefQual().getGroupsOfMyTypeQuery();
initialize: function() {
},
getGroupsOfMyTypeQuery: function() {//main
var myGroups = this.getMyGroups();
var myGroupsTypes = this.getGroupTypesOfGroups(myGroups);
var groupsOfMyTypes = this.getGroupsOfType(myGroupsTypes);
var encQry = 'sys_idIN' + groupsOfMyTypes.join(",");
return encQry;
},
getMyGroups: function() {
return groupsStr;
},
getGroupTypesOfGroups: function(groups) {
return groupTypes;
},
getGroupsOfType: function (groupTypes) {
/*look here for customer on the other table to make*/
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 04:50 PM
You can pass the current object as mentioned below:
javascript:new YourScriptInclude().yourFunctionName(current)
Then in the script include, you need to define a parameter in the function:
yourFunctionName: function (incidentRecord) {
//perform the logic with incidentRecord
//return reference qualifier string
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2019 05:02 PM
I'm sorry if this is a bad question, but I'm confused when it comes to getting from
getGroupsOfMyTypeQuery: function(current) {//main
to my bottom function
getGroupsOfType: function (groupTypes) {
How would I get current through all of my other functions to the bottom one?