Populate parent depending on the Service Offering

Prateek kumar
Mega Sage

Hello Experts

I'm having a tough time populating a set of values to a glidelist based on a different field.

I have two different Glide Lists(Business service and Service Offerings). Each Service Offering will have a Business Service as a parent which i want to populate on change of Service Offering. I'm using Client callable Script Include and an onchange client script but had no luck in achieving. Any help or lead would be greatly appreciated.

Script Include:

getDetailsChange: function(){

var retVal = [];
var ci_service = this.getParameter('sysparm_record');
var service = ci_service.split(',');
//gs.log(service[0], 'prateek log');
for(var i=0; i< service.length; i++){
var obj = {};
var details = new GlideRecord('service_offering');
details.addQuery('sys_id',service[i]);
details.query();
while(details.next())
{
//retVal = details.parent.getDisplayValue();
retVal.push(details.parent.toString()+'');
gs.log(details.parent.toString(), 'prateek');
}

}
return retVal;
},

type: 'getOfferingDetails'
});

 

OnChange Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var ci_service = g_form.getValue('u_service_offering');
alert(ci_service);
var ga = new GlideAjax('getOfferingDetails');
ga.addParam('sysparm_name','getDetailsChange');
ga.addParam('sysparm_record',ci_service);
ga.getXML(CallBack);

function CallBack(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_business_service', answer);
alert(answer);

}

}


Please mark my response as correct and helpful if it helped solved your question.
-Thanks
1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you provide more information on exactly what isn't working? Are you getting a result in your answer and unable to populate the glidelist with it or are you not getting a result at all from the server?

From looking at the script I did notice that you're trying to return an array from the script include to the client script, which won't work. If it's just values you might just do the following when returning the value back to the client script.

Change:
return retVal;
To:
return retVal.join();

The glidelist is going to be expecting a comma separated list of sys_ids anyway.

 

View solution in original post

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Could you provide more information on exactly what isn't working? Are you getting a result in your answer and unable to populate the glidelist with it or are you not getting a result at all from the server?

From looking at the script I did notice that you're trying to return an array from the script include to the client script, which won't work. If it's just values you might just do the following when returning the value back to the client script.

Change:
return retVal;
To:
return retVal.join();

The glidelist is going to be expecting a comma separated list of sys_ids anyway.

 

Hey Brad

Awesome that did it, but the only thing i noticed is when i pick 2 service offerings with the same Parent(Business Service), it alerts with the parent values but sets the glide list value to empty. Any ideas/thoughts?


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

I kind of figured it out Brad. You are awesome 

find_real_file.png


Please mark my response as correct and helpful if it helped solved your question.
-Thanks