I want to Hide 2 fields(in portal view) of a record producer to non-managers, please advise.

Sree Harsha
Tera Contributor
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sree Harsha 

Do this

1) onLoad catalog client script and GlideAjax with UI Type-Portal

Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	checkRecordPresent: function(){
		// check if logged in user is manager of someone or not
		var gr = new GlideRecord('sys_user');
		gr.addQuery('manager', gs.getUserID());
		gr.setLimit(1);
		gr.query();
		return gr.hasNext().toString();
	},
	
    type: 'checkRecords'
});

Client Script:

function onLoad() {

    var ga = new GlideAjax('checkRecords');
    ga.addParam('sysparm_name', "checkRecordPresent");
    ga.getXMLAnswer(function(answer) {
        if (answer == 'false') { // means logged in user is non manager
            g_form.setDisplay('variable1', false);
            g_form.setDisplay('variable2', false);
        } else {
            g_form.setDisplay('variable1', true);
            g_form.setDisplay('variable2', true);
        }
    });
    //Type appropriate comment here, and begin script below

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Sree Harsha 

Do this

1) onLoad catalog client script and GlideAjax with UI Type-Portal

Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	checkRecordPresent: function(){
		// check if logged in user is manager of someone or not
		var gr = new GlideRecord('sys_user');
		gr.addQuery('manager', gs.getUserID());
		gr.setLimit(1);
		gr.query();
		return gr.hasNext().toString();
	},
	
    type: 'checkRecords'
});

Client Script:

function onLoad() {

    var ga = new GlideAjax('checkRecords');
    ga.addParam('sysparm_name', "checkRecordPresent");
    ga.getXMLAnswer(function(answer) {
        if (answer == 'false') { // means logged in user is non manager
            g_form.setDisplay('variable1', false);
            g_form.setDisplay('variable2', false);
        } else {
            g_form.setDisplay('variable1', true);
            g_form.setDisplay('variable2', true);
        }
    });
    //Type appropriate comment here, and begin script below

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar  Thank you so much, It worked for me!!