G_Form Set Value not Populating Lookup Select Box
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2020 12:06 PM
Hi, I have built a form for one of our departments. They want to convert an Incident to a specific Request Form. I hav create a button and pass the Incident Number to that Request Form. They want to pull the Category, Subcategory, Component fields into variables on the Request.
In my catalog client script, I set it up to pull the incident number into the client script and below is the code.
function onLoad() {
//Populate the variables with the parameters passed in the URL
//Use the 'getParmVal' function below to get the parameter values from the URL
var num = getParmVal('sysparm_number');
var getUserIn = new GlideAjax('getIncidentInfo');
getUserIn.addParam('sysparm_name','getIncident');
getUserIn.addParam('sysparm_incident_ticket', num);
getUserIn.getXML(getInfo);
function getInfo(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
g_form.setValue('incident_ticket', num);
g_form.setValue('requested_by', obj.requested_by);
g_form.setValue('category', obj.category);
g_form.setValue('i_short_description', obj.short_description);
g_form.setValue('i_description', obj.description);
g_form.setValue('subcategory', obj.subcategory);
g_form.setValue('component', obj.component);
g_form.setValue('component2', obj.component2);
}
}
function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
And this is my script include
var getIncidentInfo = Class.create();
getIncidentInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIncident: function(){
var obj = {};
var ticket = new GlideRecord("incident");
if(ticket.get(this.getParameter('sysparm_incident_ticket'))){
//Reference Field will return sys_id. Use getDisplayValue() to return display value
obj.requested_by = ticket.getValue('u_requested_by');
obj.category = ticket.getValue('category');
obj.subcategory = ticket.getValue('subcategory');
obj.component = ticket.getValue('u_component');
obj.component2 = ticket.getValue('u_component_2');
obj.short_description = ticket.getValue('short_description');
obj.description = ticket.getValue('description');
}
return JSON.stringify(obj);
},
type: 'getIncidentInfo'
});
The trouble I am having is the following fields are not setting the value.
g_form.setValue('subcategory', obj.subcategory);
g_form.setValue('component', obj.component);
g_form.setValue('component2', obj.component2);
Is there a way to force it? I have tried an onChange script for each variables, but it doesn't always complete it. It may stop at Component.
Any help would be appreciated.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2020 06:32 PM
It was set to All. I tried it with Desktop to and it still doesn't work. I am unsure why this is happening. I will keep trying to troubleshoot.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2020 07:09 PM
Alright, sorry that none of the responses to your post have been helpful to you.
We're merely providing standard troubleshooting though, so if it's something else, it may be some anomaly within your instance. As in another client script or something else that is conflicting, etc.
Please mark any reply that has been Helpful as Helpful if it has been thus far.
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
09-25-2020 09:10 PM
Can you share what form you mean? Is that still the catalog item/requested item?
In your script you are using
var num = getParmVal('sysparm_number');
Are you sure that is also in the url for the back-end/technician view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2020 12:32 PM
You can check the following:
- Do the Values (not display value) match from the ticket table and the request?
- Are there any reference qualifiers defined on the variables on the request?
- Alert/log the values and see if they are retrieved correct.
Let me know if this helps! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2020 12:38 PM
I do have a reference qualifer. This is the only way to pull the data from the Category/Sub Category/Component fields.
The big issues is the values are not there yet until Category is set, then subcategory fields show. And the same for Component, if Subcategory is there then the fields will show on Component.