Script is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 05:58 AM
Hello exports,
We have "sn_ind_tmt_orm_order_task" table and "u_site_name" field and related list "sn_ind_tmt_orm_order_characteristic_value" table and "characterstic" is "sitename" this have charactestic_value will be updated through the payload .
Requirement is .
We want to update characterstic value in "u_site_name" field . below script is working but issue is its
updating same value for all the task. please support on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:06 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:37 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2024 06:46 AM
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);