- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 02:31 PM
Hello Experts,
SAM-Calculate Asset Refresh Eligibility which runs weekly (OOB) check if the useful life is exceeded or not. If exceeded, if flags the "Eligible for Refresh " field to yes.
My question is, is there any way that we can created REQ/ RITM on behalf of the owner of the asset when the "Eligible for Refresh " flagged as true after the job and the RITM runs through it's own flow.
If this is doable, kindly advise me on how we can do this. Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:45 PM
HI @Shan14 ,
I trust you are doin great.
This can e achived by using the scheduled job along with the cart API
// Query assets where 'Eligible for Refresh' is true
var assetGR = new GlideRecord('alm_asset'); // Assuming 'alm_asset' is the table name
assetGR.addQuery('eligible_for_refresh', true);
assetGR.query();
while (assetGR.next()) {
// Check if a REQ/RITM already exists for this asset to avoid duplicates
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('asset', assetGR.sys_id);
ritmGR.query();
if (!ritmGR.next()) { // If no RITM exists for this asset
// Create a new REQ/RITM for the asset owner
var cart = new Cart("newCart", assetGR.owned_by.toString()); // Assuming 'owned_by' is the field storing the owner's sys_id
var item = cart.addItem('YOUR_CATALOG_ITEM_SYSID'); // Replace with your catalog item sys_id
// Set any necessary variables for the catalog item
cart.setVariable(item, 'variable_name1', 'value123');
cart.setVariable(item, 'variable_name2', 'value123');
var req = cart.placeOrder();
gs.info("Created REQ: " + req.number + " for Asset: " + assetGR.asset_tag);
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 10:45 PM
Hi @Shan14
Sample code to raise the request from script:
var cart = new Cart("newCart", "user_sysid");
var item= cart.addItem('give_item_sysid'); //map item sysid here
cart.setVariable(item,'variable_name1,'value123');
cart.setVariable(item,'variable_name2','value123');
var req_id = cart.placeOrder();
gs.info(req_id.number);
Use this accordingly in your logic.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:59 AM
Thank you so much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 11:45 PM
HI @Shan14 ,
I trust you are doin great.
This can e achived by using the scheduled job along with the cart API
// Query assets where 'Eligible for Refresh' is true
var assetGR = new GlideRecord('alm_asset'); // Assuming 'alm_asset' is the table name
assetGR.addQuery('eligible_for_refresh', true);
assetGR.query();
while (assetGR.next()) {
// Check if a REQ/RITM already exists for this asset to avoid duplicates
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('asset', assetGR.sys_id);
ritmGR.query();
if (!ritmGR.next()) { // If no RITM exists for this asset
// Create a new REQ/RITM for the asset owner
var cart = new Cart("newCart", assetGR.owned_by.toString()); // Assuming 'owned_by' is the field storing the owner's sys_id
var item = cart.addItem('YOUR_CATALOG_ITEM_SYSID'); // Replace with your catalog item sys_id
// Set any necessary variables for the catalog item
cart.setVariable(item, 'variable_name1', 'value123');
cart.setVariable(item, 'variable_name2', 'value123');
var req = cart.placeOrder();
gs.info("Created REQ: " + req.number + " for Asset: " + assetGR.asset_tag);
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 10:41 AM
Thank you So much.
btw, The table is alm_hardware which has the Eligible for Refresh field