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

Vamsi Sreenivas
Giga Guru

Hi, you can use the following regex:

/[a-zA-Z]+[_]*.[a-zA-Z]+[_]*.sys_id/g

this also make sure if the variable name contains underscore(_)

Can I know where you are using the regex ?

 

Regards,

Vamsi S

Community Alums
Not applicable

Hi Vamsi,

First of all, thanks for your reply. 

We have tried running the scan, it is giving some findings. But the thing is that, it still isn't showing us records in which we have multiple dot-walking.

Eg.- The records that are showing up have something like this- binding.sys_id, current.sys_id, user_name.sys_id. Basically, <object>.sys_id.

But we also want- current.user.sys_id, binding.manager.sys_id, these kinds of records. Means,             <object>.<fieldname>.sys_id .

 

Anyways Vamsi, we are still getting some findings. Thanks a lot for your response. Appreciate it.

 

And regarding your question that, where are we using the regex, we are actually developing a custom check in the Instance Scan module, which will show us all the records based on the above criteria.

 

Thanks again.

And please see if you can please help us further.

Have a nice day!

Sudhangshu

@sudhangshu - Right, but my question is where exactly you are querying for the regex pattern? like how you are identifying the script components all across the system?

 

Further, to improve the regex based on you shared your shared examples, the below regex identifies one or more number of dot walking sys_id's.

Ex: current.sys_id,

grIncident.opened_by.sys_id,

grIncident.opened_by.location.sys_id

([a-zA-Z]+[_]*.[a-zA-Z]+[_]*.)+sys_id

 

Regards,

Vamsi S

 

Community Alums
Not applicable

Hi Vamsi,

Right now, didn't get the time to try the second regex that you sent, as we are currently busy with something else. Will let you know as we try it.

And regarding your query, we are actually validating this particular regex across all the script fields present on the platform, so that we get the findings and later they can be corrected. 

We are putting all the tables in an array, and later running a query on this regex and iterating through each table.

I hope this answers.

 

Thanks,

Sudhangshu