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

Sure Ulka. If you have a follow up query do let me know.

Else please mark my answer as correct and close this thread for others.

Regards,

Shloke

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

Regards,
Shloke

Ulka1
Tera Contributor

Hi Shloke,

 

Now the requirement is changed such that instead of logged in user, we have to fetch the value of location and jobtitle for the "Subject Person" field (This is a reference field for sys_user table like caller field for the incident form) which is on the HR Situation case Management form. 

 

Please could you assist me for the same.