- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 05:22 AM
How do I clear a variable value using an onLoad Client Script?
The catalog item auto fills a variable (employee type) based on the requested for. Requested for auto fills when the submitter opens the catalog item.
Using an onChange script, the employee type does not populate unless the requested for is changed.
Using an onLoad script, the employee type populates but if I change the 'requested for' the employee type does not change.
What can I do to get this to populate correctly?
Thank you for any help you can offer...
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:06 AM
Use the onchange client script and remove the isloading check on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 05:53 AM
When I use an onChange script, the employee type does not populate because requested for is populated.
When I use onLoad, the employee type populates based on the requested for, however if I change the requested for, the employee type does not change.
How can I set this up to have the employee type auto populate onLoad and change if the requested for us changed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:08 AM
Hi @rachelconstanti ,
Please try the below client script & script include & let me know if it works or not
Client script: onChange
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('EmployeeUtils');
ga.addParam('sysparm_name', 'FetchEmployeeType');
ga.addParam('sysparm_requestor', g_form.getValue('requested_for'));
ga.getXML(rollback);
function rollback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_employee_type',answer);//Use proper backend names of the variable
}
}
Script Include: Client Callable should be true
var EmployeeUtils = Class.create();
EmployeeUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
FetchEmployeeType: function(){
var requestor = this.getParameter('sysparm_requestor');
var employeeType = '';
var gr = new GlideRecord('sys_user');
if(gr.get(requestor)){
employeeType = gr.u_employee_type;//Use proper backend names of variables
}
return employeeType;
},
type: 'EmployeeUtils'
});
Thanks,
Danish