I want a regular expression which captures 'gr.user.sys_id', where, 'gr' and 'user' are dynamic and 'sys_id' will always be there.

Community Alums
Not applicable

Hi all,

I want to create a custom check on the 'Instance Scan' module, where we have got the recommendation as follows:

" Reference fields already store the Sys ID of the referenced record. Using gr.fieldname.sys_id is a dot-walk and instructs the platform to perform another query only to return the same value. This is an unnecessary overhead. Call the field as normal. For example, gr.getValue('reference_field'). "

We somehow want to capture all the records in which the script field has this expression-

<glideRecord object>.<fieldname>.sys_id.

We have tried using the following regular expression, but somehow it's not showing up any findings.

"/[a-zA-Z]\.[a-zA-Z]\.sys\/_id/"

Any kind of help would be appreciated.

 

Thanks & Regards,

Sudhangshu Das

1 ACCEPTED SOLUTION

Improvement to the regex (though this is still a naive solution)

/\b[a-zA-Z_$][a-zA-Z\d_$]*\s*\.(?:\s*\w+\s*\.)+\s*sys_id\b/

Though even this could be missed by some weird coding practices...

var someValue = gr /* Some comments in the middle of my expression*/
	.some_ref /* this is the blah blah record */
	.some_column /* some explaination of the value we are getting*/

maybe I'm being overly pedantic but I'd look at AST, feels like the juice is worth the squeeze for someone to figure out the AST parser method to catch these as it would be a commonly desired check

View solution in original post

10 REPLIES 10

Community Alums
Not applicable

Hi John,

 

Thanks for the solution. What we were looking for, we got that from the regular expression you have posted. It's giving us the findings as we want. Thanks again.

In case of any other doubts, will mention that under the same thread.

 

Regards,

Sudhangshu