How to Override Default for Requested For Field

ajlabate
Kilo Expert

The Requested for field is always set to whoever is creating the request (the person presently logged in).   I'm trying to make it something different and all my attempts have failed.   Ultimately, I'd like it to be the name of the person that is entered into the Variable (Requested for).   I checked the dictionary for the field and saw that it had a default value as javascript:gs.getUserID()     I removed this default value but the field gets set anyway.   I tried to set it in the beginning of the workflow with a Run Script activity to the variable entry submitted by the user but that does nothing.   No matter what I do, the field is always set to the person entering the request.   I need that person to be able to designate someone else as the requested for person.   Any ideas?

 

This is the script in the workflow:

var reqRecord = current.request.getRefRecord();

reqRecord.requested_for = current.variable_pool.requested_for;

1 ACCEPTED SOLUTION

yes sir.. just replace the entire script with the below and it should work like magic.



___________________




function onChange(control, oldValue, newValue, isLoading) {


   


    if (newValue){


          var gr = new GlideRecord('sc_cart');


          gr.addQuery('user', g_user.userID);


          gr.query();


          gr.next();


          gr.requested_for = newValue;


          gr.update();


    }


}


View solution in original post

55 REPLIES 55

you don't have to do anything to the script other than paste it into an onchange client script in the item.. and set the variable that it is looking to change   <at the top right of the form> to requested_for   ...



the functions onchange etc are built into the system and declaring them in the top line makes them available...



the only line of code   you should have to alter at all is



gr.requested_for = newValue;



and you would only need to change this if your requested for is named anything other than requested_for.



the issue is that by default the requested for on the CART.. <not the item> is g_user   this script simply sets the carts requested for to the requested for variable.... you can tell it is working because on the checkout screen the requested for won't be the logged in user but the requested for on the variable.


I will amend this with ONE issue that is inherient in doing this .. and it applies anyway you set the items/request requested for to the variable.. if you have a person order items for multiple people in one cart the requested for will be the requested for on the last item added to the cart.


Thanks.   That should not pose a problem as no one uses it like that (at least not yet   ).


Hi Doug, have you found anyway to prevent the requester from entering more than 1 requested for if more than 1 item is added to the cart?



We have been experiencing this issue, and at the minimum I would like a message box telling them they have already selected a requested for - or something like that.



In our instance every item shares a variable set called Requested For. The first variable asks Is this Request for You and is a Yes/No variable.


If they select Yes, the cart requested for is set to the current user.


If they select No, a user reference field is displayed asking them to select the user the request is for. This item requested for is then passed to the cart requested for.



It would be awesome if SNOW would let us cascade variables in the cart without using an order guide 🙂 but in the meantime - we can surely build a catch in for this issue?



Thanks


Teri


we check no cart on all items which isn't perfect but works mostly