- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 06:32 AM
Hello,
I have functionality on my application where when you lookup an agent it populates 4 other fields.
This functionality is working perfectly fine, the issue I'm coming across is when I clear the reference field (u_name),
the other 4 fields retain their values.
I'm looking for help on how to clear the number, advisor region, district and manager fields once the Name field is cleared.
I've attached my info below.
Any help would be great.
//Script Include
var AdvisorInformation = Class.create();
AdvisorInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAdvisorInfo: function (){
var advisorArray = [];
var advisorDetails = new GlideRecord ('sys_user');
advisorDetails.addQuery('sys_id',this.getParameter('sysparm_advisorName'));
advisorDetails.query();
while(advisorDetails.next()){
var advisor = {};
advisor.number = advisorDetails.u_primary_agent_number.toString();
advisor.region = advisorDetails.location.u_region.toString();
advisor.district = advisorDetails.location.u_district.toString();
advisor.manager = advisorDetails.manager.getDisplayValue();
advisorArray.push(advisor);
}
return JSON.stringify(advisorArray);
},
type: 'AdvisorInformation'
});
//Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (!newValue){
g_form.clearValue('u_advisor_number');
g_form.clearValue('u_advisor_region');
g_form.clearValue('u_advisor_district');
g_form.clearValue('u_district_manager');
}
var advisorGA = new GlideAjax ('AdvisorInformation');
advisorGA.addParam('sysparm_name', 'getAdvisorInfo');
advisorGA.addParam('sysparm_advisorName', newValue);
advisorGA.getXMLAnswer(AdvisorInformationParse);
function AdvisorInformationParse(response){
var myObj = JSON.parse(response);
for (var i=0; i< myObj.length; i++){
g_form.setValue('u_advisor_number',myObj[i].number);
g_form.setValue('u_advisor_region',myObj[i].region);
g_form.setValue('u_advisor_district',myObj[i].district);
g_form.setValue('u_district_manager',myObj[i].manager);
}
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding