Script to auto assign a group when specific keyword is typed in short description

Renu4
Tera Contributor

Hello Community,

I would like to automate the assignment of group when short description field contains the key words [HORIZON].

I have used assignment rules and assigned it but i want to convert this text to lowercase and assign it and some how it does not seem to work.

I have tried: 

if(current.short_description.toLowerCase().indexOf('[HORIZON]') >=0){
current.assignment_group = "a0a698c71ba9115073876313604bcb7f";
}

currentlly in my filtering condition i am providing the condition manually but i want to hard code it as the user can type in mixed case as well.for eg[HoriZON] or something similar

Any guidance would be appreciated.

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

Why do you want the GlideRecord query? I think it is not required in your case. You can try the below code:

Note: Pass the sys_id of the assignment group. Make sure Before is selected in When

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

    // Add your code here
    if(current.short_description.toLowerCase().indexOf('[horizon]') >=0){
        current.assignment_group = "a0a698c71ba9115073876313604bcb7f"; // Pass the sys_id of assignment group
    }
})(current, previous);

 

Thank you,
Palani

View solution in original post

5 REPLIES 5

Vamsi Sreenivas
Giga Guru

Hi Renu,

You can use assignment rule script with the same script you wrote in the question, where you can use .toLowerCase().

OR I would say you can simply use an update BR where you can use .toLowerCase(). Did you see any challenges in this approach?

 

Mark my answer as HELPFUL / CORRECT if this help resolve your issue.

Regards,

Vamsi S

 

Vamsi Sreenivas
Giga Guru

Hi Renu,

I missed this in my first read, when you are using .toLowerCase then the HORIZON should be in small case.

i.e.,

if(current.short_description.toLowerCase().indexOf('[horizon]') >=0){ //horizon in small case
current.assignment_group = "a0a698c71ba9115073876313604bcb7f";
}

Mark my answer as HELPFUL / CORRECT if this help resolve your issue.

Regards,

Vamsi S

Hi Vamsi,

Thanks for your response. 

I have few questions.

If i have to run a business rule and script it do i choose anything in the filtering conditions?

Second do i write a complete glide record function like this

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

    // Add your code here


    var gr = new GlideRecord("incident");
    gr.addQuery("short_description", current.short_description);
    gr.query();
    if (gr.next()) {

        var horizon = ['a0a698c71ba9115073876313604bcb7f']; // Static Sys_ID of User which needs to be added to Watch List
        if(current.short_description.toLowerCase().indexOf('[horizon]') >=0){
		current.assignment_group = horizon";
}

})(current, previous);

Hi,

Why do you want the GlideRecord query? I think it is not required in your case. You can try the below code:

Note: Pass the sys_id of the assignment group. Make sure Before is selected in When

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

    // Add your code here
    if(current.short_description.toLowerCase().indexOf('[horizon]') >=0){
        current.assignment_group = "a0a698c71ba9115073876313604bcb7f"; // Pass the sys_id of assignment group
    }
})(current, previous);

 

Thank you,
Palani