onload catalog client script g_form.getReference in Portal not working

dilini
Giga Expert

Hi, Following unload script is not working on new Portal. I tried to use GlidAjex and realized GlideAjex is not supporting portal too. does getRefrence also not support portal??

function onLoad() {
//Type appropriate comment here, and begin script below
var supervisorRef = g_form.getReference('bulkmail_supervisor_name', popSupervisorInfo);

function popSupervisorInfo(supervisorRef) {
if (supervisorRef.phone) {
g_form.setValue('bulkmail_supervisor_phone', supervisorRef.phone);
}
}

Thank you!

Dilini

1 ACCEPTED SOLUTION

If you run this do you see an alert with the supervisor name?

function onLoad() {
    // Query for the supervisor
    var supervisorRef = new GlideRecord('sys_user');
    supervisorRef.addQuery('sys_id', g_form.getValue('bulkmail_supervisor_name'));
    supervisorRef.query(popSupervisorInfo);
}

function popSupervisorInfo(supervisorRef) {
    if (supervisorRef.next()) {
alert('Supervisor: ' + supervisorRef.name);
        if (supervisorRef.phone) {
            g_form.setValue('bulkmail_supervisor_phone', supervisorRef.phone);
        }
    }
}

View solution in original post

32 REPLIES 32

You mean to say sys_user table?

Does this work on the Regular ServiceNow UI? Issue is only with Service Portal. Which version of ServiceNow are you on? 

 

 


Please mark this response as correct or helpful if it assisted you with your question.

sorry for late reply. No this doesn't work on the regular ServiceNow. We have Istanbul. 

A couple of things to check.

1)  Change the 'UI type' field to 'All' on your client script.  Does the script work in the standard catalog interface?

2)  Ensure that there's actually a value in the 'phone' field

3)  Check your browser error console for any errors.  Other client scripts can interfere with this one if they have issues.

4)  This EXACT script is working in my instance.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	// Query for the supervisor
	g_form.getReference('bulkmail_supervisor_name', popSupervisorInfo);
}

function popSupervisorInfo(supervisorRef) {
	if (supervisorRef.phone) {
		g_form.setValue('bulkmail_supervisor_phone', supervisorRef.phone);
	}
}

Client script form is set like this...

find_real_file.png

If you still can't get it working after checking these things I'm happy to jump on a webex with you to figure it out.  Just let me know.

Thank you very much for your help. I will check all the things you mention and let you know soon!

I checked followings:

A couple of things to check.

1)  Change the 'UI type' field to 'All' on your client script.  Does the script work in the standard catalog interface?

YES I change to 'UI type' to 'All'.  That helped! Script which  has getReference method not compatible with Portal. 

2)  Ensure that there's actually a value in the 'phone' field

YES. I checked to make sure there is value for the field 'phone' in sys_user record.

3)  Check your browser error console for any errors.  Other client scripts can interfere with this one if they have issues. 

YES. I ensured there are any UI policies or other catalog client scripts interfere. 

4)  This EXACT script is working in my instance.

my instance - Istanbul 11b

However the your GlideRecord script work - Thank you!