Fix Script not working to match a field in a table from another table

Deo Christian V
Tera Contributor
gs.info ("START - Match CDL from Sales Table SG/SSG/Attributes Status");
var count = 0;
var grCD = new GlideRecord('u_client_delivery_custom_fullfiller_view');
grCD.addEncodedQuery("u_custom_req_item.numberINRITM17518582,RITM17518588");
grCD.setLimit(2); //change the number based on the # of records in the envi.
grCD.query();

while(grCD.next()){
    var grSales = new GlideRecord('x_amspi_acn_asb_dsm_sales_report');
    grSales.addQuery('ritm_ssw_number' + grCD.u_custom_req_item.number);
    grSales.setLimit(2);
    grSales.query();

    if(grSales.next()){
        if (grSales.sg_ssg_attributes_status != grCD.u_sg_ssg_attributes_status){
            grCD.u_sg_ssg_attributes_status = grSales.sg_ssg_attributes_status();
            grCD.update();
            count++;
        }
    }
}
gs.info("Count of updated records [CDLv2]: "+count);
2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@Deo Christian V 

try this

I assume field "ritm_ssw_number" is string type

gs.info("START - Match CDL from Sales Table SG/SSG/Attributes Status");
var count = 0;
var grCD = new GlideRecord('u_client_delivery_custom_fullfiller_view');
grCD.addEncodedQuery("u_custom_req_item.numberINRITM17518582,RITM17518588");
grCD.setLimit(2); // Change the number based on the # of records in the environment.
grCD.query();

while (grCD.next()) {
    var grSales = new GlideRecord('x_amspi_acn_asb_dsm_sales_report');
    grSales.addQuery('ritm_ssw_number', grCD.u_custom_req_item.number);
    grSales.setLimit(2);
    grSales.query();
    while (grSales.next()) {
        if (grSales.sg_ssg_attributes_status != grCD.u_sg_ssg_attributes_status) {
            grCD.u_sg_ssg_attributes_status = grSales.sg_ssg_attributes_status;
            grCD.update();
            count++;
        }
    }
}
gs.info("Count of updated records [CDLv2]: " + count);

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

View solution in original post

Brad Bowman
Mega Patron

This line is using incorrect syntax so it will either be ignored causing a random record to be returned, or the script will fail

    grSales.addQuery('ritm_ssw_number' + grCD.u_custom_req_item.number);

Use one of these options

    grSales.addQuery('ritm_ssw_number' , grCD.u_custom_req_item.number);
    grSales.addEncodedQuery('ritm_ssw_number=' + grCD.u_custom_req_item.number);

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@Deo Christian V 

try this

I assume field "ritm_ssw_number" is string type

gs.info("START - Match CDL from Sales Table SG/SSG/Attributes Status");
var count = 0;
var grCD = new GlideRecord('u_client_delivery_custom_fullfiller_view');
grCD.addEncodedQuery("u_custom_req_item.numberINRITM17518582,RITM17518588");
grCD.setLimit(2); // Change the number based on the # of records in the environment.
grCD.query();

while (grCD.next()) {
    var grSales = new GlideRecord('x_amspi_acn_asb_dsm_sales_report');
    grSales.addQuery('ritm_ssw_number', grCD.u_custom_req_item.number);
    grSales.setLimit(2);
    grSales.query();
    while (grSales.next()) {
        if (grSales.sg_ssg_attributes_status != grCD.u_sg_ssg_attributes_status) {
            grCD.u_sg_ssg_attributes_status = grSales.sg_ssg_attributes_status;
            grCD.update();
            count++;
        }
    }
}
gs.info("Count of updated records [CDLv2]: " + count);

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

This works. Thank you 

 

Brad Bowman
Mega Patron

This line is using incorrect syntax so it will either be ignored causing a random record to be returned, or the script will fail

    grSales.addQuery('ritm_ssw_number' + grCD.u_custom_req_item.number);

Use one of these options

    grSales.addQuery('ritm_ssw_number' , grCD.u_custom_req_item.number);
    grSales.addEncodedQuery('ritm_ssw_number=' + grCD.u_custom_req_item.number);

This works. Thank you