- 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:05 PM
Can you try below script and let me know what you see in the log Also I am using getValue
getLicenseInfo: function() {
var software = this.getParameter('sysparm_request_type');
gs.log('+++++software is+++++'+software);
var license = new GlideRecord ('u_software_catalog');
license.addQuery('sys_id',software);
license.query();
while(license.next()){
if(license.getValue('u_license_needed') == true)
{
return yes;
}
return no;
}
}
});
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 12:49 PM
Sorry, I copied the wrong script (updated above) only difference being it returns true or false, not yes or no. I'll be adapting this to use in workflow as well which is what i copied.
When I remove the commented parts of the client script its returning true or false appropriately in the regular view of servicenow. So I'm pretty certain the script include is sending the needed info, its the client script that's tripping me up. Not sure what to do to replace the commented parts and still get what I need. I'm pretty certain I've accomplished this before but at the moment my brain is drawing a blank.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 01:21 PM
If it is a matter of just one field, you can actually do a GlideRecord or a getReference as well instead of using GlideAjax
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2018 12:06 PM
Just so I understand this, you have a variable on the catalog item that references the u_software_catalog table, and you want to show/hide another variable based on the u_license_needed field on the u_software_catalog table? Or is there an extra table dotwalk in there somewhere?