generating request from Schedule job

rahul67
Kilo Expert

i have been trying to generate Request ticket from Schedule Jobs using the following script

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//gives sys_id of catalog item
var item = cart.addItem('5104596487ed0910d0d4ca27cebb35fc', 1);
item.setVariable("requested_for", gs.getUserID());
var rc = cart.placeOrder();

 

everything is works fine but not displaying the Requested_for value by default. Please help

 

find_real_file.png

1 ACCEPTED SOLUTION

I have written this in a Scheduled Job as you need, but in case you need to write or use this in an Server side function you can do it as well :

Scheduled Job screenshot for reference as well:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

23 REPLIES 23

no use

not worked

 

Hi Martin , can you help me how to auto populate Short description and Description

shloke04
Kilo Patron

Hi,

Please use the script below to achieve your requirement:

createRequest();

function createRequest() {
    var cart = new Cart();
    var item = cart.addItem('e212a942c0a80165008313c59764eea1'); // Replace your catalog item sys id here
    var getUser = getUserDetails();
    cart.setVariable(item, 'requested_for', getUser);
    var rc = cart.placeOrder();


}

function getUserDetails() {
    var user = new GlideRecord('sys_user');
    user.addQuery('sys_id', gs.getUserID());
    user.query();
    if (user.next()) {
        return user.sys_id.toString();
    }
}

This is working for me as shown below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

I have written this in a Scheduled Job as you need, but in case you need to write or use this in an Server side function you can do it as well :

Scheduled Job screenshot for reference as well:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke