How to create business rule on catalog task (sc_task) table?

Annie10
Tera Contributor

Hello,

How to create a business rule that grab all the Catalog Tasks that belong to a RITM?

Here is what I have, but it did not work.  Please provide suggestions.  Thank you

find_real_file.png

HERE IS THE ENTIRE CODE:

When to run:  after insert and update

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

    var grTasks = new GlideRecord('sc_task');
    grTasks.addQuery('parent', current.sys_id);
    grTasks.query();
    while (grTasks.next()) {
        //do something with the task record
        grTasks.short_description = current.short_description;
        grTasks.decription = current.decription;
        grTasks.assignment_group = "Service Desk";
        grTasks.cmdb_ci = "Software";
        grTasks.update();
    }
})(current, previous);

 

1 ACCEPTED SOLUTION

AnirudhKumar
Mega Sage
Mega Sage

I will make an assumption of what it it you are looking for. Every catalog task that gets created as part of one particular catalog item needs to be updated with the RITM's short description and description in the corresponding fields, (I hope I'm right?)

 

Ideally this needs to be done on the Workflow or the Flow designer that is tagged to the catalog item. It's far more easier to maintain that way. Anyway, if for some reason you really have to do it with a BR, then have the BR on Catalog Task table and run it before insert.

Here's your code:

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

    current.short_description = current.request_item.short_description;
    current.description = current.request_item.description;

})(current, previous);

 

 

Also, this can be achieved without any code with a flow designer. Give it a try 🙂

View solution in original post

9 REPLIES 9

AnirudhKumar
Mega Sage
Mega Sage

I will make an assumption of what it it you are looking for. Every catalog task that gets created as part of one particular catalog item needs to be updated with the RITM's short description and description in the corresponding fields, (I hope I'm right?)

 

Ideally this needs to be done on the Workflow or the Flow designer that is tagged to the catalog item. It's far more easier to maintain that way. Anyway, if for some reason you really have to do it with a BR, then have the BR on Catalog Task table and run it before insert.

Here's your code:

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

    current.short_description = current.request_item.short_description;
    current.description = current.request_item.description;

})(current, previous);

 

 

Also, this can be achieved without any code with a flow designer. Give it a try 🙂

Thank you so much for helping AnirudhKumar!

I learned how to do it in flow designer, but I don't understand how to do it in Business Rule.

Your revised code works really well.  Could you please show me the script to run only for 1 catalog item.  I need to learn it in Condition and in filter condition.

find_real_file.png

find_real_file.png

 

Awesome! 

To add the logic in the Condition field, this is the code:

current.request_item.item == '<<sysid of your item>>'

(we are simply dot walking to the related RITM record through the request_item field on the catalog task form and then accessing the item field on the RITM form which holds the catalog item sysid)

 

To add the logic on the filter, here's how you'd do:

1. In the filter, search for Request item and select Request item

2. Now scroll to the bottom of the filter and select Show Related Fields  

3. Again search in the filter for Request item and select Request Item -> Requested Item fields

4. Again search in the filter for Item and select Item

5. Select your item from the reference in the 3rd box.

 

I took a video of the process, but unable to attach it here. Let me know if you got it from the description

 

 

Hello AnirudhKumar,

I understood it clearly.  Thank you so much for your time and effort!