Create a catalog item automatically and populate fields

Rajkumar Bommal
Tera Contributor

Hi 
I created a custom table , when a record is inserted in the custom table i want to create a new catalog item in sc_cat_item
Acceptance criteria:
this is done when a record is inserted in custom table , i have already done using business rule and records also creating in sc_cat_item,
But flow designer is not inserting in the catlog item record 

 

this is the business rule i have used to create catalog item record

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

    var catItem = new GlideRecord('sc_cat_item');
    catItem.initialize();
    catItem.name = current.name;
    catItem.short_description = "Automatically created ";
    catItem.active = true;
    catItem.sc_catalogs.addQuery('title', 'Service Catalog');
    catItem.category = '11e43cf683a0a21091c71c29feaad3b9';
    //catItem.flow_designer_flow = gs.getProperty('emplee_standard_flow');

    var catItemSysId = catItem.insert();

    if (catItemSysId) {
        current.catalog_item = catItemSysId;
        current.update();
       
        var variableSetId = 'd9e0a07a8364621091c71c29feaad3fe';
        var catItemVarSet = new GlideRecord('io_set_item');
        catItemVarSet.initialize();
        catItemVarSet.sc_cat_item = catItemSysId;
        catItemVarSet.variable_set = variableSetId;
        catItemVarSet.insert();
       
       
    }

})(current, previous);
4 REPLIES 4

Shivalika
Mega Sage

Hello @Rajkumar Bommal 

 

Why aren't you using flow designer and just copy paste the values. That is much simpler than whole scripting it. And it's sure to work. I have a flow designer attached to insertion in custom table and it works fine. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Voona Rohila
Kilo Patron
Kilo Patron

Hi @Rajkumar Bommal 

 

- I would not suggest this option of creating new catalog item every time, instead you can create one default catalog item which has a dropdown field which shows the name choices from your custom table( because only name is dynamic and remaining are static values )

- If your requirement is always creating item - As only name is dynamic and remaining are static values so make sure when you are inserting catalog item, perform a check.

 

And yes the flow mapping is correct, make sure you set proper flow sys_id and that flow should work for any item dynamically.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajkumar Bommal 

why are you creating catalog item using script?

Is this a business requirement?

is the flow published? is the sys_id of the flow correct?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Vishal Jaswal
Giga Sage

Hello @Rajkumar Bommal 

Have a discussion with stakeholder related to this requirement and discuss the complete flow of catalog item like it has a flow/workflow which creates Requested item which then undergoes approval flows if required etc.

In the meantime, if it is only for learning purpose, then here is the sample flow:

VishalJaswal_0-1743443278057.png

VishalJaswal_1-1743443291276.png

 

VishalJaswal_2-1743443302602.png

 


Hope that helps!