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

@sudhangshu, Yes it makes sense. Thanks!

Community Alums
Not applicable

Hi Vamsi,

 

We tried the above, and as I said previously, we need to capture records where there is multiple dot walking happening. Single dot-walk to the SysID is acceptable.

So for that we have found the solution. The regular expression given by @John Dewhurst in the thread below is working as expected.

Thanks for your time.

 

 

Regards,

Sudhangshu

Vasantharajan N
Giga Sage
Giga Sage

Instance Scan findings will provide you the original record that has a problem. Better you can go into the actual record and rectify the issue and do a rescan of the check that identifies the record. 


Thanks & Regards,
Vasanth

John Dewhurst
Kilo Guru

/\b\w+\.\w+\.sys_id\b/
would be a naive way to do it, variable names can actually include dollars and numbers as well so would have to cater for that, then there could be whitespace so it might actually look more like...

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

Though this would catch comments and the like as well, you will need to use AST functionality for a good test that won't return false positives, I'm not an AST expert though yet so someone else would need to help with that.

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