- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 10:12 AM
Hi Developers,
I have a problem :
In the catalog item, there is a checkbox(If the logged in user is a partner); this checkbox should be checked if the requested_for user's career level is Manager or consultant. Career level is a drop down field with multiple designations(Analyst, Manager, Senior manager,...)
Kindly help with the script.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 10:25 AM - edited 11-01-2023 10:26 AM
Hi @developersn ,
In that case please create an onChange script on requested for field as below
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Use GlideAjax to get the career level of the requested_for user
var ga = new GlideAjax('CheckCareerLevel');
ga.addParam('sysparm_name', 'getCareerLevel');
ga.addParam('sysparm_user', g_form.getValue('requested_for')); // Assuming 'requested_for' is the variable name for the user reference field
ga.getXML(parseResponse);
}
function parseResponse(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer === 'Manager' || answer === 'Consultant') {
g_form.setValue('variables.partner_checkbox', true); // Check the checkbox if career level is Manager or Consultant
} else {
g_form.setValue('variables.partner_checkbox', false); // Uncheck the checkbox for other care
er levels
}
}
Script Include:
Client Callable should be true
var CheckCareerLevel = Class.create();
CheckCareerLevel.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCareerLevel: function() {
var userId = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user'); // Assuming 'sys_user' is the table name for the User table
if (gr.get(userId)) {
return gr.getValue('career_level');
}
return '';
},
type: 'CheckCareer
Level'
});
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 10:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 10:18 AM
@Danish Bhairag2 Yes. It's there on User table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 10:20 AM
So the checkbox should be checked only when the requested for person is a manager or consultant correct?
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 10:23 AM - edited 11-01-2023 10:23 AM
That's correct. if the requested for user's Career level is Manager or Consultant then this checkbox on catalog item should be checked.