Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Try/Catch to do catch GlideRecord SetValue in ScriptInclude

Bruno Leclerc
Kilo Expert

Hi,

I can't catch this stupid error :

Let's say I initialize this GlideRecord in a stupid way. When calling setValue method throws an error that I am not able to catch.

Why ? Thanks

 

// ----------------------------------------------------------------------

var gr=new GlideRecord(null); // Missing table name
try
{
    gr.setValue(100,"toto");
}
catch(e)
{
    gs.log("Never goes here.");
}

// ----------------------------------------------------------------------

 

1 ACCEPTED SOLUTION

Allen Andreas
Tera Patron

Hi,

That's because no error is thrown? I believe.

You can try:

// ----------------------------------------------------------------------

var gr=new GlideRecord(null); // Missing table name
gr.query();
try
{
    gr.setValue(100,"toto");
}
catch(e)
{
    gs.log("Never goes here.");
}

// ----------------------------------------------------------------------

So I added in a gr.query(); to now get it going.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

9 REPLIES 9

Allen Andreas
Tera Patron

Hi,

That's because no error is thrown? I believe.

You can try:

// ----------------------------------------------------------------------

var gr=new GlideRecord(null); // Missing table name
gr.query();
try
{
    gr.setValue(100,"toto");
}
catch(e)
{
    gs.log("Never goes here.");
}

// ----------------------------------------------------------------------

So I added in a gr.query(); to now get it going.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

Yea and really I'd think you'd want to "try" it all, so this would work too:

try
{
var gr=new GlideRecord(null); // Missing table name
gr.query();
    gr.setValue(100,"toto");
}
catch(e)
{
    gs.info("Never goes here.");
}

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

Yea, you could also move all of the code inside the try, and then that works too:

// ----------------------------------------------------------------------

try
{
var gr=new GlideRecord(null); // Missing table name
gr.query();
    gr.setValue(100,"toto");
}
catch(e)
{
    gs.log("Never goes here.");
}

// ----------------------------------------------------------------------

Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Lots of replies saying to do what I did lol...if anyone wants to mark Helpful...that'd be fantastic 😉


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!