Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Failure of executeRule Function to compile

Not applicable
Newbie here.  Any Help appreciated.  I get this error when trying to save:
Could not save record because of a compile error: JavaScript parse error at line (3) column (16) problem = missing ; before statement (<refname>; line 3)
 
(function executeRule(current, previous /*null when async*/)
{
    Var makeVIP = new GlideRecord('sys_user');
    Var q1 = makeVIP.addQuery('title', 'COTAINS', 'VICE');
    q1.addOrCondition('title', 'CONTAINS', 'Vice');
    q1.addOrCondition('title', 'CONTAINS', 'CHIEF');

    while (makeVIP.next()) {
        makeVIP.vip = true;
        gs.info("ADMIN: " + makeVIP.name + "with title: " + makeVIP.title + " is now a VIP.");
        makeVIP.update();
    }

})(current, previous);
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Community Alums 

update as this

(function executeRule(current, previous /*null when async*/) {
    var makeVIP = new GlideRecord('sys_user');
    makeVIP.addQuery('title', 'CONTAINS', 'VICE');
    makeVIP.addOrCondition('title', 'CONTAINS', 'Vice');
    makeVIP.addOrCondition('title', 'CONTAINS', 'CHIEF');
    makeVIP.query(); // Execute the query

    while (makeVIP.next()) {
        makeVIP.vip = 'true'; // Use string for boolean
        gs.info("ADMIN: " + makeVIP.name + " with title: " + makeVIP.title + " is now a VIP.");
        makeVIP.update();
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Community Alums 

update as this

(function executeRule(current, previous /*null when async*/) {
    var makeVIP = new GlideRecord('sys_user');
    makeVIP.addQuery('title', 'CONTAINS', 'VICE');
    makeVIP.addOrCondition('title', 'CONTAINS', 'Vice');
    makeVIP.addOrCondition('title', 'CONTAINS', 'CHIEF');
    makeVIP.query(); // Execute the query

    while (makeVIP.next()) {
        makeVIP.vip = 'true'; // Use string for boolean
        gs.info("ADMIN: " + makeVIP.name + " with title: " + makeVIP.title + " is now a VIP.");
        makeVIP.update();
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Not applicable

Thanks.  That did it!