Business Rule Script help, Please

Gemma4
Mega Sage

Hello,

The good news is I have everything almost working but I am having trouble with my business rule script. Here is a summary of my progress and the script details. 

I created a configuration item called ProjectManagement

I created a variable called configuration item and set the default value to the sys id

This part enabled the configuration to be added(hidden)on the catalog item

I then created a business rule to copy the variable configuration to the Request field called configuration item. So far all of the above has worked as expected. 

Then I created a business rule to set the request state to New if the configuration item is Project management. This last  part isn't working and changing the state. I set the table to Request, when to run is after, filter confidition is Configuration item changes to ProjectManagement. 

 

Anyone have any ideas why? 

 

 

//(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
//var gr= new GlideRecord("sc_req_item");
//gr.addQuery('request', current.sys_id);
////gr.addQuery('cat_item','52a1fd631b47215053545243604bcb35');
// //gr.addQuery('cat_item','7c3fbb0b97c321102ab77d100153af5b'); project catalog
// gr.addQuery('cmdb_ci','98ebee741ba4711053545243604bcb74'); //project cmdb value
gr.query();
//if(gr.next()){
//current.request_state= 'New';
//// grRequestItems.state = 10; // "Stopped" state change if required
// }
 
 
//})(current, previous);
 
 
 
(function executeRule(current, previous /*null when async*/) {
 
var req = new GlideRcord('sc_request');
req.addQuery('sys_id', current.request);
req.query();
while (req.next()) {
req.request_state = 'New';
req.update();
}
})(current, previous);
6 REPLIES 6

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @Gemma4 ,

In the second business rule, you have a typo in the GlideRecord . Instead of GlideRcord, it should be GlideRecord.

Kindly mark correct and helpful if applicable 

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Gemma4 ,

you can try this code

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

    // Check if the "Configuration item" field has changed to "ProjectManagement"
    if (current.configuration_item.changesTo('ProjectManagement')) {

        // Update the request's state to "New"
        var req = new GlideRecord('sc_request');
        if (req.get(current.request)) {
            req.request_state = 'New';
            req.update();
        }
    }
})(current, previous);
Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)