g_scratchpad not working as expected

Sarabjeet1
Tera Contributor

Hi,

I have a simple requirement to show field message if user is SLT true. I have used Display BR to get the value from user table and called that in my client script. g_scratchpad is passing undefined value to CS (checked with alert). Not sure if i am making any syntax mistake or something else. Please find below both and let me know what i am doing wrong.

Display BR 

Sarabjeet1_0-1701179920602.png

 

 

Client script

Sarabjeet1_1-1701179167814.png

 

 

 

 

14 REPLIES 14

@Sarabjeet1 

share the client script, it should work fine ideally, why don't you use parseBool

use below line in display BR

g_scratchpad.vipslt = parseBool(gr.getValue("u_vip_slt'));

 

and in onload client script use

if(g_scratchpad.vipslt == "true")

g_form.showFieldMsg("requested_for", "your message", "info");

 

Best Regards
Aman Kumar

This should work, here is what I tried, you can compare and correct. Your client script should be onload and not onchange

 

Also in your BR you are using gs.getUserID(), which is not right, you should use current.requested_for instead as you are fetching the flag for requested for and not the logged in user.

BR

AnuragTripathi_0-1701181282967.png

 

 

Client SCript

AnuragTripathi_1-1701181302361.png

 

 

Result

AnuragTripathi_2-1701181323497.png

 

-Anurag

Hi @Anurag8 and @Aman Kumar S 

I am still stuck with the same issue. i tried everything you both suggested but still no luck.

BR

(function executeRule(current, previous /*null when async*/ ) {
   
    var gr = new GlideRecord('sys_user');
    gr.get(gs.getUserID());
    //g_scratchpad.vipslt = parseBool(gr.getValue("u_vip_slt"));   [Tried with this as well]
    g_scratchpad.vipslt = gr.u_vip_slt;
    gs.log('sarab' + g_scratchpad.vipslt);
 
CS
function onLoad() {
   //Type appropriate comment here, and begin script below
alert('its here');
    if (g_scratchpad.vipslt == true) {
        // alert('best' + a);
        g_form.showFieldMsg('requested_for', 'New user', 'info');
        alert('good');
        //Type appropriate comment here, and begin script below

    }
}

Anurag Tripathi
Mega Patron
Mega Patron

On your display BR you are setting g_scratchpad.slt (on line 3) and then on the next line and also the client scrit yiou are trying to use g_scratchpad.vipslt 

You are using wrong Variable name. change line 3 to use g_scratchpad.vipslt 

-Anurag

Sagar Pagar
Tera Patron

Hi @Sarabjeet1,

 

Your display BR and Client scripts should be on RITM table.

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow