How to reference field in another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2023 11:22 AM
I'm writing a client script that will allow me to send an alert if a value on a dot-walked table is true. The Client script is being written for the Incident table but need to reference a field in the sys_user table. What is the correct format for referencing that table via the script below?
Example
function onSubmit() {
//Alerts the CMR creator if they try to peer review their own change
var caller_flag = g_form.getValue('caller.u_flagged');
if (caller_flag === true){
alert('You cannot peer review a change that you are creating.','Warning');
return false;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:07 AM
@Meshia ,
You can also do one thing create a dummy field on form say "flagged?" and make it hidden using UI policy
and on load of form just store the value of flagged from user table in that field and based on that you can decide on "onSubmit" whether you have to show alert or not
funcion onLoad(){
var data = g_form.getReference("caller",mydata);
function mydata(data){
g_form.setValue('flagged',data.u_flagged);
}
}
ANd in the onSubmit script you can check,
if(g_form.getValue("flagged") == true){
alert('your message here');
return false;
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 09:41 AM
Hello@Meshia : Why don't you create a scratchpad variable [in a display BR] & call it from your client script to check if the flagged==true?
Regards
ServiceNow Consultant
United Kingdom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:00 AM
I've never done that before. I'll have to research it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 10:10 AM
Hi @Meshia,
In order to stop the form submission or providing alert message, you can use before update/insert BR. Where you can stop the form subimission/updation and easily show a message as well. It will be easy to get the dot walk values in Business rule.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var caller_flag = current.getValue('caller.u_flagged');
if (caller_flag === true) {
gs.addErrorMessage('You cannot peer review a change that you are creating.');
current.setAbortAction(true);
}
})(current, previous);
Please mark this as correct and helpful if it solved your query.
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2023 12:49 PM
Thank you all for your help. I was able to get it to work using a UI Policy.