How to show value of a choice field based on the logged in users location and job title

Ulka1
Tera Contributor

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.

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Ulka 

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);

find_real_file.png

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

6 REPLIES 6

ersureshbe
Giga Sage
Giga Sage

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.

Regards,
Suresh.

Ulka1
Tera Contributor

 

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.

shloke04
Kilo Patron

Hi @Ulka 

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);

find_real_file.png

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Ulka1
Tera Contributor

Thank you very much Shloke. I will check it.

Once again thank you.