- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2020 12:54 AM
Hi I'm creating a scheduled task which will generate a pref-filled service request (Request, Request Item and Catalog Task). I know how to setup the schedule but I'm having trouble generating all three task and have them linked to each other.
I tried doing it via templates but I can only either create one, but I need all three created and linked to each other. I tried Next Related Child Template and Link Element but this doesn't link the request items to request or catalog taks, they are created separately.
I also tried using Cart but it doesn't generate any ticket;
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('52ded723db92eb4081a0a03114961964');
var rc = cart.placeOrder();
gs.addInfoMessage(rc.number);
Please help! thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 07:55 PM
SOLVED!!!
Go to System Definition-> scheduled Job-> New
Select Automatically run a script of your choosing
and use this script:
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('b6088febdbc4f7c0a9a28e35059619d5'); // sys_id of catalog item
infoMessage += 'Created cart with id: ' + cartId + '\n';
var requestingUser = new GlideRecord('sys_user');
var reqUserName = 'guest.email'; // The requested for user
requestingUser.addQuery("user_name", reqUserName);
requestingUser.query();
if(requestingUser.next()) {
infoMessage += 'Loaded user: ' + requestingUser.name + '\n';
cart.setVariable(item, "requested_for", requestingUser.sys_id);
cart.setVariable(item, "company", requestingUser.company);
} else {
infoMessage += 'ERROR: Failed to load user: ' + reqUserName + '\n';
}
// Set the short_description, description and business_justification
cart.setVariable(item, "short_description", "Your Short Description");
cart.setVariable(item, "description", "Your Description");
cart.setVariable(item, "business_justification", "Your Business Justification");
// Place the order
var rc = cart.placeOrder();
infoMessage += 'Request Number: ' +rc.number;
gs.info(infoMessage);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2020 07:55 PM
SOLVED!!!
Go to System Definition-> scheduled Job-> New
Select Automatically run a script of your choosing
and use this script:
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('b6088febdbc4f7c0a9a28e35059619d5'); // sys_id of catalog item
infoMessage += 'Created cart with id: ' + cartId + '\n';
var requestingUser = new GlideRecord('sys_user');
var reqUserName = 'guest.email'; // The requested for user
requestingUser.addQuery("user_name", reqUserName);
requestingUser.query();
if(requestingUser.next()) {
infoMessage += 'Loaded user: ' + requestingUser.name + '\n';
cart.setVariable(item, "requested_for", requestingUser.sys_id);
cart.setVariable(item, "company", requestingUser.company);
} else {
infoMessage += 'ERROR: Failed to load user: ' + reqUserName + '\n';
}
// Set the short_description, description and business_justification
cart.setVariable(item, "short_description", "Your Short Description");
cart.setVariable(item, "description", "Your Description");
cart.setVariable(item, "business_justification", "Your Business Justification");
// Place the order
var rc = cart.placeOrder();
infoMessage += 'Request Number: ' +rc.number;
gs.info(infoMessage);