Pass Categories Dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 12:08 PM - edited 03-11-2024 08:31 PM
Hello everyone,
I am working on configuring ISR assessment... My requirement says that create a field on assessment form named categories that referes to all the assessment metric categories and whichever categories user selects on form he should be able to take up the assessment only for those categories. When I had a check system is pushing all the existing categories for ISR assessment which I have to restrict. I tried creating above business rule on asmt_m2m_category_assessment table, thinking that it will work.
But it is incorrectly inserting records.
BR type: after insert
Table name: asmt_m2m_category_assessment
Could anyone please help me out here.
Many thanks,
Ujjwala
var assessmentRecord = current.vendor.getDisplayValue();
var categories = current.u_categories.split(',');
var gr = new GlideRecord('asmt_m2m_category_assessment');
gr.addQuery('sys_id', assessmentRecord);
gr.query();
while(gr.next()) {
var existingCategories = gr.category.toString().split(',');
// Add new categories
for(var i = 0; i < categories.length; i++) {
if(existingCategories.indexOf(categories[i]) === -1) {
existingCategories.push(categories[i]);
}
}
// Remove categories not present in u_categories
for(var j = 0; j < existingCategories.length; j++) {
if(categories.indexOf(existingCategories[j]) === -1) {
existingCategories.splice(j, 1);
}
}
gr.category = existingCategories.join(',');
gr.update();
}