How to reference field in another table

Meshia
Kilo Guru

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;
9 REPLIES 9

@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.

Sails
Kilo Sage

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

Sails
ServiceNow Consultant
United Kingdom

I've never done that before.  I'll have to research it.

Mohit Kaushik
Mega Sage
Mega Sage

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.

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Meshia
Kilo Guru

Thank you all for your help.  I was able to get it to work using a UI Policy.