Cannot use getReference method on client script , Glide ajax is the other way

Rahul84
Tera Contributor

Hi @Ankur Bawiskar /Team,

Facing one challenge to use getReference method on client script. I know the other way is to use Glide ajax call.

But I have a display business rule and have a g_scratchpad variable. 

I am having reference field "abc" on a table on which my onLoad client script is written and this "abc" field refers to other field that is having a manager field. I want the value of this manager field and needs to compare this with my g_scratchpad variable.

Pls let me know how can I use this on my client script instead of getRefernce. If Glide ajax is the way so pls provide me the logic and script for reference , how can I call my display BR on client script.

Thanks

21 REPLIES 21

Hi,

in onload client script access the g_scratchpad.SOM variable and compare it with what you want

something like this

function onLoad(){

	var loggedInUser = g_user.userID;
	if(loggedInUser != g_scratchpad.SOM){
		g_form.setReadOnly('u_abc', true);
	}

}

Regards
Ankur

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

Hi Rahul,

You can use Ankur's script in client script. However, remember one thing if field is already read only for service manager because of some ACL then making it editable through client script will not work.

I would suggest to go with ACL which is quite appropriate and simple for your requirement. You would need to create "write ACL" on abc field and use below script in script section of ACL, that's it.

var answer=current.u_service_offering.owned_by==gs.getUserID();

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP