glide evaluator

RiteshI
Tera Contributor
getDynamicValue: function(valueString, table, record, displayValue, doNA){
        var returnVal = valueString;
        var regexp = /\{([^}]+)\}/g;
        var toReplace;
        while ((toReplace = regexp.exec(valueString))){
            var replaceVal;
            var field = toReplace[1].toString();
            toReplace = toReplace[0].toString();
            var rec = new GlideRecord(table);
            if (rec.get(record)) {
                if (displayValue == true)
                    replaceVal = eval ('rec.' + field + '.getDisplayValue()');
                else
                    replaceVal = eval('rec.' + field);
               
                //If replaceVal is nil and it's not a barcode field, return 'N/A'
                if (replaceVal == '' && doNA == true)
                    replaceVal = 'N/A';
               
                returnVal = returnVal.replace(toReplace, replaceVal);
                if (this.debug == 1)
                    gs.log('BarGen: Returning dynamic value = ' + replaceVal);
            }
        }
        return returnVal;
    }---------------->want to replace eval with glide evaluator ?
 
11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@RiteshI 

The class "GlideScopedEvaluator" is used when you use scripts field and want to evaluate it.

where are you using this script?

what's your business requirement?

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

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

Hey I have a Ui script in which eval is used I want to replace it with GlideScopedEvaluator-->is it posibble

e: function() {
            var a = this.H();
            if (a.length > 0) return eval(this.B.CallFunction('<invoke name="executeCommand" returntype="javascript"><arguments><string>' + a.join("&#0;") + "</string></arguments></invoke>"))
        }-------->here
 

RiteshI
Tera Contributor

But I see in example scripts of GlideEvaluator It asks for glideRecord

@RiteshI 

UI script is client side and you cannot use GlideScopedEvaluator as it's server side.

Your use case is different

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

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

@RiteshI 

Hope you are doing good.

Did my reply answer your question?

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

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