The CreatorCon Call for Content is officially open! Get started here.

Priority to be updated before insert of a record in Case form

Community Alums
Not applicable
Hi Team,
 
We have to set priority using 3rd part integration based on  category and subcategory but its not working. 
I have written below BR Before Insert and tested usin rest explorer , it only sets as P2 high for all.
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    // var Priority=1;

    var categoryCritical = [68707172];
    var subcategoryCritical = [583595596597575581536];
    var categoryModerate = [7071];
    var subcategoryModerate = [5982052576582572574];
    var categoryLow = [71];
    var subcategoryLow = [577578579];
    var categoryHigh = [72];
    var subcategoryHigh = [535];

    var cat = current.getValue('category');
    var subcat = current.getValue('subcategory');

    if (categoryCritical.indexOf(cat) == -1 && subcategoryCritical.indexOf(subcat) == -1) {
gs.info('critical');
        current.priority=1;


    }  if (categoryModerate.indexOf(cat) == -1 && subcategoryModerate.indexOf(subcat) == -1) {
        gs.info('Moderate');
        current.priority=3;

    } if (categoryLow.indexOf(cat) == -1 && subcategoryLow.indexOf(subcat) == -1) {
gs.info('Low1');
        current.priority=4;
        
    } if (categoryHigh.indexOf(cat) == -1 && subcategoryHigh.indexOf(subcat) == -1) {
        gs.info('High');
        current.priority=2;

    }
    

})(current, previous);
5 REPLIES 5

praneeth7
Tera Guru

Hello @Community Alums 

 

I have made small changes in your script. please try this out,

(function executeRule(current, previous) {
    var categoryCritical = [68, 70, 71, 72];
    var subcategoryCritical = [583, 595, 596, 597, 575, 581, 536];
    var categoryModerate = [70, 71];
    var subcategoryModerate = [598, 2052, 576, 582, 572, 574];
    var categoryLow = [71];
    var subcategoryLow = [577, 578, 579];
    var categoryHigh = [72];
    var subcategoryHigh = [535];

    var cat = current.getValue('category');
    var subcat = current.getValue('subcategory');

    if (categoryCritical.indexOf(cat) !== -1 || subcategoryCritical.indexOf(subcat) !== -1) {
        gs.info('Critical');
        current.priority = 1;
    } else if (categoryModerate.indexOf(cat) !== -1 || subcategoryModerate.indexOf(subcat) !== -1) {
        gs.info('Moderate');
        current.priority = 3;
    } else if (categoryLow.indexOf(cat) !== -1 || subcategoryLow.indexOf(subcat) !== -1) {
        gs.info('Low');
        current.priority = 4;
    } else if (categoryHigh.indexOf(cat) !== -1 || subcategoryHigh.indexOf(subcat) !== -1) {
        gs.info('High');
        current.priority = 2;
    } else {
        // If the category and subcategory don't match any predefined values, set the priority to a default value (e.g., 5).
        gs.info('Default');
        current.priority = 5;
    }
})(current, previous);

if this helps you, Please mark my answer help and Accepted solution

Thank you

Community Alums
Not applicable

Its showing as P5 for all, not working.

Community Alums
Not applicable

Can anyone tell me why its going to Else Condition?

Community Alums
Not applicable

This is resolved Now. I needed to do ParseInt for subctegory and Category. and check for > - 1 instead !==1