- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 03:46 AM
Hi,
There is a choice field named 'project' and the choice values are A,B and C and I want to display one value ie A of this choice field for the condition 'logged in users location and job title'. (Here only A value of this choice field.
Please can anyone suggest me how we can implement this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 04:27 AM
Hi
Please write a Display Business Rule on the Table where these fields are present and use the script as below which will check logged in User Location and Job Title as below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var loggedUser = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',loggedUser);
gr.query();
if(gr.next()){
g_scratchpad.Location = gr.getDisplayValue('location');
g_scratchpad.Title = gr.getDisplayValue('title');
}
})(current, previous);
Now write a On Load Client Script on the same table and use the script as below:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.Location == 'Your value to check' && g_scratchpad.Title == 'Your value to check') {
g_form.clearOptions('Field Name where choices are there');
g_form.addOption('FieldName', 'chocieValue', 'ChocieLabel');
} else {
g_form.clearOptions('Field Name where choices are there');
g_form.addOption('FieldName', 'chocieValue1', 'ChocieLabel1');
g_form.addOption('FieldName', 'chocieValue2', 'ChocieLabel2');
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 03:50 AM
Hi,
Can you explain where you to achieve the requirement. If catalog item you should create field a called lookup select box and define the condition when you want to display the choices.
If Backend / Platform view - you should use 'Dependent Value' underneath 'sys_choice' table.
Please mark as correct answer if it helped.
Regards,
Suresh.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 04:20 AM
Hi Suresh,
Thank you for the response.
Yes, I have to achieve this requirement at Backend / Platform view . so please can you suggest me in detail how to implement this requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 04:27 AM
Hi
Please write a Display Business Rule on the Table where these fields are present and use the script as below which will check logged in User Location and Job Title as below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var loggedUser = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',loggedUser);
gr.query();
if(gr.next()){
g_scratchpad.Location = gr.getDisplayValue('location');
g_scratchpad.Title = gr.getDisplayValue('title');
}
})(current, previous);
Now write a On Load Client Script on the same table and use the script as below:
function onLoad() {
//Type appropriate comment here, and begin script below
if (g_scratchpad.Location == 'Your value to check' && g_scratchpad.Title == 'Your value to check') {
g_form.clearOptions('Field Name where choices are there');
g_form.addOption('FieldName', 'chocieValue', 'ChocieLabel');
} else {
g_form.clearOptions('Field Name where choices are there');
g_form.addOption('FieldName', 'chocieValue1', 'ChocieLabel1');
g_form.addOption('FieldName', 'chocieValue2', 'ChocieLabel2');
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2022 04:34 AM
Thank you very much Shloke. I will check it.
Once again thank you.