How to trigger business rule from record producer

babbi
Tera Expert

we have a record producer on incident table, and we have quantity variable in record producer. when user submits this record producer , based on the quantity the incident will create. but here the problem is with numbering. the newly created number is not in sequence means the old ticket number is 20, but the newly create tickets having from 22, skipping 21. so we are thinking to create a new business rule which will create incidents once the record producer submits.

please suggest how can we trigger a business rule when user submits record producer.

this is the script in record producer

if (producer.asset_i_would_like_to == "create") {
    for (var i = 0; i < producer.asset_quantity; i++) {
        var assetCreation = new GlideRecord("incident");
        assetCreation.initialize();
        assetCreation.u_campus = producer._asset_campus;
        assetCreation.u_building = producer.asset_building.getDisplayValue();
        assetCreation.u_level = producer.asset_level.getDisplayValue();
        assetCreation.location = producer.asset_location.getDisplayValue();
        assetCreation.u_cost_centre = producer.asset_asset_type.getDisplayValue();
        assetCreation.u_usage_for = producer.asset_usage_for;

assetCreation.insert();

 

2 REPLIES 2

Chandu Telu
Tera Guru
Tera Guru

Hi

Code Looks good, Can you check the below property

https://docs.servicenow.com/bundle/sandiego-platform-administration/page/administer/field-administration/task/t_PreventNumberingGaps.html

 

https://docs.servicenow.com/bundle/sandiego-platform-administration/page/administer/field-administration/concept/c_EnforcingUniqueNumbering.html

 

Thanks
Chandu Telu
Please Mark ✅ Correct/helpful, if applicable,

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you are sure there won't be any new incidents created by any other user either via UI or from some other record producer then the numbering will be fine.

Consider you submit record producer with 5 quantity so script would run 5 times

But in between the for loop if some other person submits same record producer or creates new incident from self-service or NEW button of table list the auto-numbering would be messy

Regards
Ankur

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