Tushar
Kilo Sage

Hi @akin9 

 

can you please try with below code -

 

var characteristicGR = new GlideRecord('sn_ind_tmt_orm_order_characteristic_value');
characteristicGR.addQuery('sn_ind_tmt_orm_order_task', current.sys_id); // Filter by the current order task
characteristicGR.addQuery('characteristic.name', 'sitename'); // Filter by the characteristic name
characteristicGR.query();

var siteNameValue = '';  // Initialize variable to hold the site name value

// Loop through all the records for the current task
while (characteristicGR.next()) {
    // Retrieve the characteristic_value (or characteristic_option_value) from the record
    var tempSiteNameValue = characteristicGR.characteristic_option_value; // Replace with the correct field name if different
    
    // If we find a valid site name, update the siteNameValue variable (you can adjust logic here if needed)
    if (tempSiteNameValue) {
        siteNameValue = tempSiteNameValue;
    }
}

// If a valid siteNameValue was found, update the u_site_name field
if (siteNameValue) {
    current.u_site_name = siteNameValue;
}

 

Thanks

akin9
Tera Contributor

Hi @Tushar  

Thank you for the quick reply will check and update.

 

akin9
Tera Contributor

Hi @Tushar  

I have tried the same  above script still we are facing the same issue.

from payload we posted characterstic value is ,madurai,pune and chennai still its updating pune only

pls check and support this.

(function executeRule(current, previous /*null when async*/) {

var characteristicGR = new GlideRecord('sn_ind_tmt_orm_order_characteristic_value');
characteristicGR.addQuery('sn_ind_tmt_orm_order_task', current.sys_id); // Filter by the current order task
characteristicGR.addQuery('characteristic.name', 'sitename'); // Filter by the characteristic name
characteristicGR.query();

var siteNameValue = '';  


while (characteristicGR.next()) {
    // Retrieve the characteristic_value (or characteristic_option_value) from the record
    var tempSiteNameValue = characteristicGR.characteristic_option_value; // Replace with the correct field name if different
   
    // If we find a valid site name, update the siteNameValue variable (you can adjust logic here if needed)
    if (tempSiteNameValue) {
        siteNameValue = tempSiteNameValue;
    }
}


if (siteNameValue) {
    current.u_site_name = siteNameValue;
}

})(current, previous);

Tushar
Kilo Sage

I think siteNameValue is being overwritten with the last characteristic_option_value in the loop (which happens to be pune), causing only that value to be assigned to u_site_name.

 

(function executeRule(current, previous /*null when async*/) {

    var characteristicGR = new GlideRecord('sn_ind_tmt_orm_order_characteristic_value');
    characteristicGR.addQuery('sn_ind_tmt_orm_order_task', current.sys_id); // Filter by the current order task
    characteristicGR.addQuery('characteristic.name', 'sitename'); // Filter by the characteristic name
    characteristicGR.query();

    var siteNameValue = '';   // Initialize an empty string to store the concatenated values

    // Loop through all the characteristics and concatenate their values
    while (characteristicGR.next()) {
        var tempSiteNameValue = characteristicGR.characteristic_option_value; // Fetch the characteristic value
        if (tempSiteNameValue) {
            // concatenate with a comma (or any other delimiter) if it's not the first value
            if (siteNameValue != '') {
                siteNameValue += ','; // Add a comma separator
            }
            siteNameValue += tempSiteNameValue; // Append the value
        }
    }

    // If we have any valid site name values, update the u_site_name field
    if (siteNameValue) {
        current.u_site_name = siteNameValue;
    }

})(current, previous);

 

akin9
Tera Contributor

Hi @Tushar  

I have tried the same above script but its updated like below.

Its pulling the all location from the characterstics table .FYI

But we want to achive based on each task record we need to update

could you pls help on this?

 

 

 

akin9_0-1732028502598.png