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

find_real_file.png

no use shloke

used the scritpt as you said 

find_real_file.png

didn't work Shloke

Hi,

Okay not an issue. For me it is working and have verified it as well. But no issues, please try this script now. This is also working for me:

createRequest();

function createRequest() {

    var cartId = GlideGuid.generate(null);
    var cart = new Cart(cartId);
    //add your requested item to the cart by sys_id of the catalog item
    var item = cart.addItem('e212a942c0a80165008313c59764eea1', 1);// Replace your cat item sys id here

    var rc = cart.placeOrder();
    var getUser = getUserDetails();
    var reqRecord = new GlideRecord('sc_request');
    reqRecord.get(rc.sys_id);
    reqRecord.requested_for = getUser;
    reqRecord.update();

}

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

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

No bro not working , i dnt know why. just copied your code and tried but not working

 

Hi Shloke, how to auto populate short description and description for this