Task are not getting created through Business rule.

Munna1
Tera Contributor

Hello team,

Here I have developed a catalog item and when it is filled and submitted would create a Request under it, Along with this, I want a Catalog Task to be automatically created through BR. Here BR is getting triggered through flow but tasks are not getting created. I have checked by adding logs. but logs added in the task table are not showing up.

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

 

 

HERE IS THE ENTIRE CODE: 

(function executeRule(current, previous /*null when async*/ ) {
    var stock = current.stockroom.getDisplayValue();
    var req = new GlideRecord("sc_request");
    req.addQuery("number", rc.number);
    req.query();
    if (req.next()) {
        var ritm = new GlideRecord("sc_req_item");
        ritm.addQuery("request", req.sys_id);
        ritm.query();
        if (ritm.next()) {
            ritm.cmdb_ci = current.ci;
            ritm.short_description = 'SRC (Stockroom Manager) to physically release the asset ';
            ritm.description = 'This is a notification the asset as you deem necessary. Asset in the Stockroom: ' + stock ;
            ritm.update();
            var sctask = new GlideRecord("sc_task");
            sctask.addQuery("request_item", ritm.sys_id);
            sctask.query();
            if (sctask.next()) {
                sctask.cmdb_ci = current.ci;
                sctask.assignment_group = current.stockroom.assignment_group;
                sctask.short_description = 'SRC (Stockroom Manager) to physically release the asset ' ;
            sctask.description = 'This is a notification the asset as you deem necessary Asset in the Stockroom: ' + stock ;
                sctask.update();
            }
    }
}
})(current, previous);

 

9 REPLIES 9

HI @Community Alums 

I have tried by adding logs in the middle of the script. But these logs are not showing. is there any error in this part of the script.

 

var ritm = new GlideRecord("sc_req_item");
        ritm.addQuery("request", req.sys_id);      
        ritm.query();
        if (ritm.next()) {
            gs.log("LH task 3");
            ritm.cmdb_ci = current.ci;
            //ritm.configuration_item = current.ci;
            ritm.short_description = 'SRC to physically release the asset ;
            ritm.description = 'This is a notification the Asset is in the Stockroom ;
            ritm.update();
            var sctask = new GlideRecord("sc_task");
            sctask.addQuery("request_item", ritm.sys_id);
            sctask.query();
            if (sctask.next()) {
                gs.log("LH task 4");
                sctask.cmdb_ci = current.ci;
                sctask.assignment_group = current.stockroom.assignment_group;
                sctask.short_description = 'SRC to physically release the stockroom.';
            sctask.description = 'This is a notification for the Asset is in the Stockroom;
               sctask.update();
 
 

Community Alums
Not applicable

Hi @Munna1 ,

I checked your given script you are not closing the string, I fixed that code please refer below 

var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", 'a25428b093318a100d5170918bba10b4');
ritm.query();
if (ritm.next()) {
    gs.log("LH task 3");
    ritm.cmdb_ci = current.ci;
    ritm.configuration_item = current.ci;
    ritm.short_description = 'SRC to physically release the asset' ;
    ritm.description = 'This is a notification the Asset is in the Stockroom' ;
    ritm.update();
    var sctask = new GlideRecord("sc_task");
    sctask.addQuery("request_item", ritm.sys_id);
    sctask.query();
    if (sctask.next()) {
        gs.log("LH task 4");
        sctask.cmdb_ci = current.ci;
        sctask.assignment_group = current.stockroom.assignment_group;
        sctask.short_description = 'SRC to physically release the stockroom.';
        sctask.description = 'This is a notification for the Asset is in the Stockroom';
           sctask.update();
    }
}

 

Please mark my answer correct and helpful if this works for you

 

Thanks and regards 

Sarthak

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @Maddysunil ,

 

Why Business rule ? why not do it with the flow/workflow which is associated with the catalog ? Any reason why Business rule.. ?


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

@Sohail Khilji 

Thanks for pointing out, Ideally he should be doing it using flow/workflow as a best practice but he mentioned I want a Catalog Task to be automatically created through BR in his question along with the tried code so suggested few logs to debug.

AnimeshP_96
Tera Guru

Hi @Munna1 
As a best practice when a catalog item is submitted you can either use flow or workflow as a best practice with no code.

with flow or workflow this can be easily achieved using "create task " activity.


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh