- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 11:55 AM
Hi All, so I'm trying to reference a field from the record being selected on the form. I have it working on the back end up the g_form option doesn't work on the portal. I'm trying to figure out how to do this without using that. When it that piece out i get a null value for answer. You can see the commented out piece that's causing the issue on service portal but without I'm getting a null.
Script include is this:
var SoftwareRequiresLicense = Class.create();
SoftwareRequiresLicense.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLicenseInfo: function() {
var software = this.getParameter('sysparm_request_type');
var license = new GlideRecord ('u_software_catalog');
license.addQuery('sys_id',software);
license.query();
while(license.next()){
if(license.u_license_needed == true)
{
return true;
}
if(license.u_license_needed == false)
{
return false;
}
}
}
});
Client Script is this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//var result = g_form.getReference('request_type').sys_id;
var ga = new GlideAjax('SoftwareRequiresLicense');
ga.addParam('sysparm_name', 'getLicenseInfo');
//ga.addParam('sysparm_request_type',result);
ga.getXML(myResponseParse);
}
function myResponseParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer == 'true') {
g_form.setDisplay('software_requires_license', true);
} else {
g_form.setDisplay('software_requires_license', false); }
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 03:27 PM
I think you can simplify this by doing everything from the client side using getReference with a callback. I would try this in your client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqType = g_form.getReference('request_type', getReqType);
}
function getReqType(reqType) {
var licenseNeeded = reqType.u_license_needed;
g_form.setDisplay('software_requires_license', licenseNeeded);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 12:40 PM
Sounds like you got the idea. I'll also be using a similar logic in the workflow to determine who the approval goes to.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 03:27 PM
I think you can simplify this by doing everything from the client side using getReference with a callback. I would try this in your client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var reqType = g_form.getReference('request_type', getReqType);
}
function getReqType(reqType) {
var licenseNeeded = reqType.u_license_needed;
g_form.setDisplay('software_requires_license', licenseNeeded);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 07:34 AM
That is brilliant. I actually haven't really made use of getReference much before so that seems like something I'll be making use of going forward.
If I could impose further. If I'm trying to base a workflow IF condition on that same true/false box being checked for the workflow selected, what would you use to do that? My first attempt failed but I have some other ideas, however my deadline to fix this is also today so any help would be huge.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 07:37 AM
I may not have the right syntax off the top of my head, but something like this should work:
answer = ifScript();
function ifScript() {
var ifAnswer = '';
var licenseNeeded = current.variables.u_license_needed;
if (licenseNeeded) {
ifAnswer = 'yes';
} else {
ifAnswer = 'no';
}
return ifAnswer;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 07:55 AM
That didn't work, it returned a no when it should of a yes. I think the issue lies in the answer part but I could be wrong. Will keep playing with the script. I deeply appreciate the help. If you'd like I can start a new question for this.