G_Form Set Value not Populating Lookup Select Box

Dazler
Mega Sage

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.

12 REPLIES 12

Allen Andreas
Administrator
Administrator

Hi,

What do you mean is there a way to force it?

That script looks correct and you're parsing the object (which was stringified on SI) and so your keys and values should all be there. Have you verified the contents of the return from your SI?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I see your responses below in another chain, but have you verified what values are within your object? That that part is actually working?

Having a reference qual on the field shouldn't matter, I believe, when using setValue and pushing it in there. You're also filling in the appropriate fields in the appropriate order, so it should be working as you're meeting the criteria for the selections to show up in the other fields, etc.

Example for testing. I have a knowledge reference field with a reference qual set at the dictionary level to only reference IT KB articles. However, I created a script that executes code and that sets that field to a security incident KB article using setValue and it works fine.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

I am noticing that the setValue is not working in the itil view, but it populates on the portal.  This form is not currently visible on the client portal.

Is there a reason it does not show on the technician view?

For the UI Type for the client script, do you have it set to just Portal possibly?

find_real_file.png

Can you try it on just Desktop? Or is it All? If All, then it should still work in standard UI.

You may want to also check other Client Scripts and see if anything is flushing that onLoad as well.

Check the order for this client script and maybe try and make it run last (larger number).

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!