Opened by on catalog item generated from run script showing as the last person to approve the original catalog item

othomas1
Kilo Guru

Hi everyone,

I have a catalog item (work from home request) that launches another catalog item (work from home hardware) within the workflow, everything looks ok except that the opened by on the new catalog item that is launched in the workflow is being set to the last person to approve in the original catalog item, i need it to be the person who opens the work from home request, how can i change this?

 

Launch work from home request:

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('e66cb93a4f236f00259db3318110c76e', 1);

//fill in the variables on the request item form
cart.setVariable(item,'requested_for', current.request.requested_for);
cart.setVariable('opened_by', current.request.opened_by);
cart.setVariable(item,'work_at_home_coordinator', current.request.opened_by);
cart.setVariable(item, 'requested_for_supervisor', current.request.requested_for.manager);
var rc = cart.placeOrder();
workflow.scratchpad.request_number = rc.sys_id; //so it can be referenced later

 

 

 

find_real_file.png

6 REPLIES 6

Hello,

Unfortunately, I don't know what you're doing at this point or how you have it set up. But if the problem is the "opened_by" changes...as this workflow goes along...then if you capture the initial value of it, which would be who opened/submitted this record with a workflow scratchpad variable...then that's a stamp in time...meaning...it's not changing again...so you can use it later.

Are you adding any gs.log statements along the way to see what you're getting with the scratchpad variable?

You could try also try:

workflow.scratchpad.opened_by = current.opened_by.sys_id;

And see if that works, but you'd have to look at what you've got to see if it's working or not.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

ABouland
Kilo Guru

This article helped me with a similar type of issue.  If I follow the logic correctly, you can't set some fields like opened_by before the var rc = adcart.placeOrder(); statement because, technically, it doesn't exist yet.

So, once you've placed the order, you need to follow it up with an additional statement within your script to set the field on the request.

in prior attempts I've used something like:

var opened = current.request.opened_by;

var rc = adcart.placeOrder();

if (current.get('sys_id', rc.sys_id)) {
//insert any fields that need updating here
//current.work_notes = 'This is a test';

current.opened_by = opened;

current . update();


}

Watch your request numbering scheme when using the above - might skip numbers.  Article above addresses this if you read through it all.

 

Alternately, you might try:

var rc = adcart.placeOrder();

rc.update;

rc.opened_by = current.request.opened_by;

rc.update();