Task are not getting created through Business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 02:38 AM - edited 05-07-2024 01:29 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 02:49 AM
Please check that the necessary data (such as the current.ci and current.stockroom) is populated correctly before trying to update the request item and create the task. Check if these fields are populated with valid values by logging them. Applied few logs to debug further.
(function executeRule(current, previous /*null when async*/ ) {
try {
var stock = current.stockroom.getDisplayValue();
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = gs.getProperty('asset.release.cat.item');
cart.addItem(item);
var rc = cart.placeOrder();
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 of 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 of the asset as you deem necessary. Asset in the Stockroom: ' + stock;
sctask.update();
} else {
gs.info("No Catalog Task found for request item: " + ritm.sys_id);
}
} else {
gs.info("No Request Item found for request: " + req.sys_id);
}
} else {
gs.info("No ServiceNow Request found for order: " + rc.number);
}
} catch (ex) {
gs.info("An error occurred: " + ex);
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 03:25 AM
Hi @Munna1 ,
Can you please use below script to create new task
(function executeRule(current, previous /*null when async*/ ) {
var stock = current.stockroom.getDisplayValue();
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = gs.getProperty('asset.releae.cat.item');
cart.addItem(item);
var rc = cart.placeOrder();
var req = new GlideRecord("sc_request");
req.addQuery("number", 'REQ0010468');
req.query();
if (req.next()) {
gs.print("Inside if")
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request", req.sys_id);
ritm.query();
if (ritm.next()) {
ritm.cmdb_ci = '46b6e9b1a9fe198100abe515a5dbaba1';
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: ';
// ritm.update();
var sctask = new GlideRecord("sc_task");
sctask.addQuery("request_item", ritm.sys_id);
sctask.query();
if (sctask.next()) {
gs.print("Inside if 22");
sctask.cmdb_ci = '46b6e9b1a9fe198100abe515a5dbaba1';
sctask.assignment_group = '8a4dde73c6112278017a6a4baf547aa7';
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: ';
// sctask.update();
} else {
var insertTask = new GlideRecord('sc_task');
insertTask.initialize();
insertTask.short_description = 'SRC (Stockroom Manager) to physically release the asset ';
insertTask.insert();
}
}
}
})(current, previous);
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 01:52 AM
HI @Community Alums ,
Tried with the else block but it is not showing any changes, still not creating any tasks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 02:54 AM
Hi @Munna1 ,
I checked once more in my PDI and it is not going in your else part because may be your RITM is already exist. If RITM is already present it will update else it will create new record.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak