How to check comma seperated field values in gliderecord query.

Ssinha4
Tera Contributor

Hi All,

We have field on our custom table where we store comma separated values in string type field.

Ssinha4_0-1727444765626.png

We have a inbound action email script  but not working.

Ssinha4_1-1727444911132.png

Let me know how can we achieve this?

 

Thank you in advance

1 ACCEPTED SOLUTION

Rajesh Chopade1
Mega Sage

hi @Ssinha4 

To check for comma-separated field values in a GlideRecord query, you need to properly parse the values from the field and compare them against your criteria. Check bellow script once and let me know its working or not:

var gr = new GlideRecord('your_custom_table'); // Replace with your actual table name
gr.addEncodedQuery('u_recipient=' + recipient); 
gr.addNotNullQuery('u_vendor'); 
gr.query();

while (gr.next()) {
    var vendors = gr.u_vendor; 

    if (vendors) {
        // Split the vendors into an array
        var vendorArray = vendors.split(',');

        // Trim whitespace and check if the sender is in the vendor array
        for (var i = 0; i < vendorArray.length; i++) {
            if (vendorArray[i].trim() === sender) {
                // Match found - remaining code here
                gs.info('Match found for sender: ' + sender + ' in vendors for record: ' + gr.sys_id);
                // Add your additional logic here
                break; // Exit loop if match is found
            }
        }
    }
}

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

View solution in original post

1 REPLY 1

Rajesh Chopade1
Mega Sage

hi @Ssinha4 

To check for comma-separated field values in a GlideRecord query, you need to properly parse the values from the field and compare them against your criteria. Check bellow script once and let me know its working or not:

var gr = new GlideRecord('your_custom_table'); // Replace with your actual table name
gr.addEncodedQuery('u_recipient=' + recipient); 
gr.addNotNullQuery('u_vendor'); 
gr.query();

while (gr.next()) {
    var vendors = gr.u_vendor; 

    if (vendors) {
        // Split the vendors into an array
        var vendorArray = vendors.split(',');

        // Trim whitespace and check if the sender is in the vendor array
        for (var i = 0; i < vendorArray.length; i++) {
            if (vendorArray[i].trim() === sender) {
                // Match found - remaining code here
                gs.info('Match found for sender: ' + sender + ' in vendors for record: ' + gr.sys_id);
                // Add your additional logic here
                break; // Exit loop if match is found
            }
        }
    }
}

 

i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh